Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it possible to compose a piece of SQL to retrive data from two tables where the second table may or may not have a value.

e.g.
 Select t1.name, t2.diplomatype
from studentmaster t1, resultmaster t2
where t1.result = t2.result
or t1.result is null


Desired Ouitput
Name DiplomaType
---- -----------
Tom Pass
Mary Honours
Jack
Liz Pass

... Or do I need to use a stored proocedure?
Posted
Comments
Manas Bhardwaj 5-Jan-11 6:12am    
Looks like this thread has a bad karma. All the answers have 1 Vote :)
Rajesh Anuhya 5-Jan-11 6:36am    
Why all answers are voted 1 ???????????? :)
Ger Hayden 5-Jan-11 9:34am    
I've just voted on 4 of the 5 anwsers. I'll have to look at the other later. Nothing less than a 4 awarded. Trouble is all those 1's are weighing down some very specific, accurate and helpfull answers

Yes offcourse Use MySQL Outer JOIN.

See Here[^]
 
Share this answer
 
v2
Comments
Ger Hayden 5-Jan-11 9:33am    
As with Ans 3, its what I needed to look up but the Rumsfeld factor got me
SELECT *
FROM
StudentMaster T1
    LEFT JOIN RESULTMASTER T2 ON
       T1.Result = T2.Result
 
Share this answer
 
Comments
Ger Hayden 5-Jan-11 9:28am    
Perfect. Exactly what I want. Looking at it I was sceptical about getting a value up out of T2 but it is a thing of beauty in its simplicity.
You may use an Outer Join:

SQL
Select t1.name, t2.diplomatype
from studentmaster t1 LEFT OUTER JOIN resultmaster t2
on  t1.code = t2.code
where 1=1


You must put the join conditions in the ON expression, and it's done.
 
Share this answer
 
v2
Comments
Ger Hayden 5-Jan-11 9:32am    
Perfect, as is Ans 1
You are looking for this [^] ????
 
Share this answer
 
Comments
Ger Hayden 5-Jan-11 9:30am    
I am. But I was having a Donald Rumsfeld moment.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900