selecting records from multiple files in mysql question
Hi, I have a question for those who know about selecting multiple fields from multiple tables in MySQL.
I have 2 test tables, Table1, and Table2 Table1: Code:
pkey flds Code:
PKEY FLDS 'select Table2.FLDS,Table1.flds from Table1,Table2 where Table2.PKEY = Table1.pkey' i get this as result: Code:
FLDS flds Like this: Code:
FLDS flds |
'select distinct Table2.FLDS,Table1.flds from Table1 join Table2 on Table2.PKEY = Table1.pkey'
hope this is what you want j. there are several ways to use "join" in mysql to be found in the mysql documentation. |
Thanks for your answer, but thats not it... this returns the same values as before. all the values that are not found in Table2 are not displayed. I want to display all from Table1 even if the corresponding link can't be found in Table2. This is important when displaying financial figures from Table1 and requesting only a description from Table2.
|
replace "join" with "left outer join"
|
Quote:
Code:
select Table2.FLDS, Table1.flds from Table1, Table2 where Table2.PKEY (+) = Table1.pkey Code:
select nvl(table2.flds, 'Link Value not Found') flds, table1.flds Code:
FLDS FLDS |
Quote:
However, I am pretty sure MySQL will do the Left Outer Join as follows: Code:
select Table2.FLDS, Table1.flds from Table1 left outer join Table2 on Table1.PKEY = Table2.PKEY Quote:
|
Hi Thanks Everybody! I Finally was able to get the result that i wanted by doing this command:
'select IFNULL(Table2.FLDS, 'Link Value not Found') FLDS, Table1.flds from Table1 left outer join Table2 on Table1.pkey = Table2.PKEY' NVL() is replaced by IFNULL() the ' (+) = ' does not work in MySQL, it returns a syntax error |
Yeah, SQL is like most other languages; there's lots of variations over and above the ANSI std (if any) ....
|
All times are GMT -5. The time now is 12:58 AM. |