
February 20th, 2013, 01:25 PM
|
|
Registered User
|
|
Join Date: Aug 2009
Posts: 4
Time spent in forums: 1 h 43 m 53 sec
Reputation Power: 0
|
|
I need help selecting records in table a that are not in table b
I need to select the records that are in table_a but not in table_b, the thing is that I also need to select the records in table_a that dont have birthdate and the records on table_b that doesnt have answers, something like this:
SELECT pacient.* FROM pacient
LEFT JOIN test
ON pacient.idpacient = test.idpacient
WHERE test.idpacient IS NULL
OR pacient.date_birth IS NULL
OR test.answer = 0
To clear it all out I need the records of the persons that dont have birthdate, or are not in table_b or that their answer is 0
HOW CAN I SELECT the records that are in table_a but not in table_b, or the records in table_a that dont have birthdate and the records on table_b that dont have answers??
Table pacient
id | name | datebirth
1 | Jose | 1989-10-15
2 | Mark | 1985-10-15
3 | Maria | 1984-10-15
4 | Liz | NULL
5 | Joe | 1990-01-25
Table test
id | id_pacient | answer
1 | 1 | 1
2 | 3 | 5
3 | 4 | 1
4 | 5 | 0
The query I want to make should display the following pacients:
2 Mark (Who doesnt appear in the test table)
4 Liz (Who doesnt have a birth date even though she has an answer in the test table);
5 Joe (Who has 0 in the answer column in the test table );
|