0

I want to display all fields in T1 based on a criterial match in T2, but I don't want to display anything from T2.

So when I query

SELECT * FROM Personal 
WHERE Personal.P_ID=Exam.P_ID
AND Exam.Level='B2'
AND Exam.Certification='Full'

I get an error (#1054 - Unknown column 'exam.Level' in 'where clause'), because I don't include the T2 (Exam) in Line 1.

But when I query

SELECT * FROM Personal, Exam 
WHERE Personal.P_ID=Exam.P_ID
AND Exam.Level='B2'
AND Exam.Certification='Full'

I get all the Exam table data returned as well.

How do I just return all the T1 (Personal) data?

I checked for previous questions and found this: Select data (join?) from only one table using an id from another table , but the answers still return the unwanted T2 data.

For example,

SELECT * FROM Personal 
JOIN Exam on Personal.P_ID = Exam.P_ID
AND Exam.Level='B2'
AND Exam.Certification='Full'
Community
  • 1
  • 1
Benjamin
  • 187
  • 3
  • 17

1 Answers1

2

First of all, don't use comma separated tables in your where clause; that's what join is for (more on this here)

To solve your problem you should change what's in your select

SELECT  Personal.*
FROM    Personal
JOIN    Exam 
ON      Personal.P_ID=Exam.P_ID
WHERE   Exam.Level='B2'
AND Exam.Certification='Full'

This will show all Personal columns, but you can of course select only some columns with

SELECT  Personal.column1, Personal.column2
Community
  • 1
  • 1
Stefano Zanini
  • 5,876
  • 2
  • 13
  • 33