I have 3 tables:
shopping:
id buyer fruit
1 1 [->] 2 [->]
2 2 [->] 2 [->]
fruits:
id fruit
1 apple
2 banana
buyers:
id buyer
1 ido
2 omri
I want to extract from the table of 'shopping' and put the values of the other tables in the row. For example: Row number one in 'shopping' should look like this:
id buyer fruit
1 ido banana
In SQL, to fetch data from multiple tables, the join operator is used. The join operator adds or removes rows in the virtual table that is used by SQL server to process data before the other steps of the query consume the data.
Double-click the two tables that contain the data you want to include in your query and also the junction table that links them, and then click Close. All three tables appear in the query design workspace, joined on the appropriate fields. Double-click each of the fields that you want to use in your query results.
You just need to join the related tables on their respective IDs:
SELECT s.id, b.buyer, f.fruit
FROM shopping s
JOIN fruits f ON s.fruit = f.id
JOIN buyers b ON s.buyer = b.id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With