How to join multipl tables?
Posted: Sat Feb 08, 2003 8:08 pm
Say I have one table (products) with these fields:
id (primary key)
product_name_id
product_descr_id
containing this:
1, 23, 300
2, 45, 324
...
and one table (lang) with these fields: (id and lang is primary key)
id
lang
lang_data
containing this:
23, 'sv', 'En bra product'
23, 'en', 'A good product'
300, 'sv', 'Jag tycker du ska köpa den här'
300, 'en', 'I think you should but this'
...
If I select product_id='1' I want a row where the
product_name_id (23) is swapped to the text in the lang table
and the product_descr_id (300) is swapped against the corresponding
text too for a choosen language.
How would I write that select statement?
SELECT * FROM products, lang WHERE products.id='1' AND lang='en' AND..??
Resulting in a row like:
1, 'A good product', 'I think you should buy this'
id (primary key)
product_name_id
product_descr_id
containing this:
1, 23, 300
2, 45, 324
...
and one table (lang) with these fields: (id and lang is primary key)
id
lang
lang_data
containing this:
23, 'sv', 'En bra product'
23, 'en', 'A good product'
300, 'sv', 'Jag tycker du ska köpa den här'
300, 'en', 'I think you should but this'
...
If I select product_id='1' I want a row where the
product_name_id (23) is swapped to the text in the lang table
and the product_descr_id (300) is swapped against the corresponding
text too for a choosen language.
How would I write that select statement?
SELECT * FROM products, lang WHERE products.id='1' AND lang='en' AND..??
Resulting in a row like:
1, 'A good product', 'I think you should buy this'