1) I have two table:
+------ +---------
topic mytask
+--------- +---------
ID | What ID | TopicID
---------- ------------
1 | A 1 | 1
2 | B
2) I have SQL as below:
SELECT
a.id, b.id
FROM
topic a
JOIN (
SELECT
b.id,b.topicid
FROM
mytask b
) b on (b.topicid=a.id)
3) I have output as below (1 ROW ONLY):
ID | ID
-------
1 | 1
My expected output is as below (2 ROW, PRIORITY TO TOPIC BY LISTING THEM ALL) :
a.ID | b.ID
-------------
1 | MATCHED - OK - TAKE IT!!!
2 | NULL or what,ever...
How can i do that?
Use a left outer join:
and simplify the query to