Reputation: 55
$sql ="(SELECT Drive.DriveID,Ram.Memory from Drive,Ram where Drive.DriveID = Ram.RamID) UNION
(SELECT Drive.DriveID,External.Memory from Drive, External where Drive.DriveID = External.ExtID)";
Suppose I want to get Ram.Name as well. How do I do this? If I use Ram.Name in the first SELECT statement it would not produce the correct result.
Any method for tackling this? I want to do it using UNION.
Upvotes: 0
Views: 72
Reputation: 74655
how about:
SELECT Drive.DriveID,Ram.Memory,Ram.Name
FROM Drive,Ram WHERE Drive.DriveID = Ram.RamID
UNION
SELECT Drive.DriveID,External.Memory,NULL
FROM Drive, External WHERE Drive.DriveID = External.ExtID
this will have NULL in the fourth column for all of the results of the second select
Upvotes: 2