Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am a newbie in mysql and I have a quick question about using the different join. Say for instance, I have 2 tables, one titled totals and another is titled goods and each contains values,

goods

ID | Name
--------
1 | coffee
2 | tea
3 | chocolate

totals

Quantity | goods ID
---------------------
40 | 3
20 | 2
10 | 1

Like this for example, the goods ID in total is the child of the ID of the goods table, but the display I want is

totals

Quantity | goods ID
-------------------
40 | chocolate
20 | tea
10 | coffee

I just want to know where the different joins would be applicable.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
154 views
Welcome To Ask or Share your Answers For Others

1 Answer

Following up from the link Juergen posted (that link is a very good reference), to achieve the result of the 3rd table you could use INNER JOIN, FULL OUTER JOIN or LEFT/RIGHT OUTER JOIN. The reason for this is because of the way your two tables are set up to match each other, hence there is no null values to worry about.

However, if the tables were set up like this:

Goods

ID | Name
--------
1 | coffee
2 | tea
3 | chocolate
4 | milk

Totals

Quantity | goods ID
---------------------
40 | 3
20 | 2
10 | 1

Then, to achieve the same result you would want to use an INNER join.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...