tags:

views:

50

answers:

3

dear i need to get query from 3 tables i try to show how i need result in picture hope this will explain every thing.

alt text

+2  A: 
SELECT a.item_id, c.menu_text, b.smenu_text, a.Item_Name
FROM a,b,c 
WHERE a.submenu_Id = b.smenu_Id
  AND b.menu_ID = c.menu_ID
Michael Pakhantsov
@Shantanu Because by default in oracle, mysql and mssql list tables separated by ',' treated as inner joins. (Same true for sqlite and postgres)
Michael Pakhantsov
A: 

Not all database engines support it but using JOINs would be better here.

Using where for join operations has been deprecated for a long time... If your database engine, I suggest you to switch to JOINs, which makes this kind of operations much easier and clearer... and sometimes, more efficient as well...

More info here: http://en.wikipedia.org/wiki/Join_%28SQL%29#Inner_join

Kharlos Dominguez
+2  A: 

You should use inner joins

SELECT a.item_id, c.menu_text, b.smenu_text, a.Item_Name
from a 
     inner join b 
        on a.submenu_id =b.smenu_id 
     inner join c
        on b.menu_id=c.menu_id
Shantanu Gupta
Don't be so melodramatic. Of course cross joins + where will work, as standardized SQL syntax it predates JOIN. For the sake of human readability you should use the newer JOIN syntax, as it is also widely supported, but any claim of portability or performance is bunk.
Recurse
You're too young to remember a time where `JOIN` did not exist, and `,` was the only way to go. I guess `,` is still supported everywhere.
pascal
pascal
@pascal and to all who questioned on this: I had little mis concept about `,` operator and as said above "You're too young to remember a time where JOIN did not exist" I do agree fully. Sorry for misinterpreting , for cross join. I hope my edit would be better now.
Shantanu Gupta