Reputation: 3618
This is a part of my query and I have a union before this query. I want to select more column in table1 under a condition.
SELECT c.ID, c.Name, c.Position, c.Email, c.ContactNumber
FROM table1 c
INNER JOIN table2 a
ON c.ID = (SELECT foreignID FROM table2 WHERE a.Name = 'someName')
WHERE Dept = 'Something' --this will return nothing since in the inner join
--the condition returns a single column and it doesn't
--satisfy the WHERE Clause
I want to select the person that satisfies the ID (which works), including the people with a Dept of Something. Is there another way in solving this, or I really need to use UNION for this. Will this affect the performance of an App, specifically Mobile App?
Upvotes: 0
Views: 206
Reputation: 12309
If I Understood your requirement correctly then Use LEFT JOIN
SELECT c.ID, c.Name, c.Position, c.Email, c.ContactNumber
FROM table1 c
LEFT JOIN table2 a ON c.ID = a.foreignID AND a.Name = 'someName'
WHERE Dept = 'Something'
Upvotes: 1