user3629216
user3629216

Reputation: 23

SQL - Selecting where a value does not exist

I have a query which selects a persons details from one table and inner joins on a table which holds exam results. This is bound as a datasource to a gridview and if there is no grade or record of the user in the results table it returns no results. Essentially i want to return all values of people even if there is no record in the results table, and if there is a result then this is displayed beside the user, otherwise N/A.

Upvotes: 1

Views: 39

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133360

You should use left join .. for this eg:

select t1.col1, t1.col2, ... t2.col1_t2, t2.col2_t2, ....
from table1 t1
left join table2 t2 on t1.id = t2.col_t1_id

left join return row where the join condition don't match too

https://dev.mysql.com/doc/refman/5.7/en/join.html

http://www.mysqltutorial.org/mysql-left-join.aspx

Upvotes: 1

Related Questions