June 13, 2011 at 7:20 pm
here is a sample simplified query:
SELECT A.name, B.address, C.country
FROM names A, addresses B, countries C
WHERE A.id=1 AND b.id=1 AND c.id=1
If there is no row where "b.id=1" then the query returns nothing. But what I would like it to do is return whatever results actually do exist:
A.name, B.address (as a null), and C.country
is there an easy way to do this in a single statement? I can copy the items to variables and do 3 queries, but my real world example is huge and not this simplistic.
thanks for any help.
June 13, 2011 at 11:56 pm
It would help if you would provide the DDL for the tables (CREATE TABLE statements), sample data for each of the tables (a series of INSERT INTO statements), expected results based on the sample data, and the code you have written so far to solve your problem.
If you provide all this information you will get better answers and tested code in return.
June 14, 2011 at 12:10 am
Three tables, no joins?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
June 14, 2011 at 1:48 am
from your Table Name I think that your Name table is master table and rest of the others are depandant on them. is it the case than
you can write like this.
SELECT A.name, B.address, C.country
FROM names A
Left join addresses B on A.Id= B.id
Left join countries C on A.id= C.id
WHERE A.id=1
June 14, 2011 at 3:07 am
ignore my last , i didnt see the joins
June 14, 2011 at 9:48 am
mukti.roy, thank you, perfect
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply