MYSQL comparison on join problem

Following a few MySQL searches

So, I look at other ways to limit the full text in the text.

I updated the submitted request ...

SELECT  t.teacherId, s1.subjectName AS name1, s2.subjectName AS name2, s3.subjectName AS name3
FROM    teacherProfile t
LEFT JOIN
        subjects s1
ON      s1.subjectId = t.subjectOne 
LEFT JOIN
        subjects s2
ON      s2.subjectId = t.subjectTwo
LEFT JOIN
        subjects s3
ON      s3.subjectId = t.subjectThree

Which works at least, but if I add.

WHERE name1 = ENGLISH'

to the end I get the Unknown column name1, can I even make a simple query on the data?

+1
source share
3 answers
SELECT  t.teacherId, s1.subjectName AS name1, s2.subjectName AS name2, s3.subjectName AS name3
FROM    teacherProfile t
LEFT JOIN
        subjects s1
ON      s1.subjectId = t.subjectOne 
LEFT JOIN
        subjects s2
ON      s2.subjectId = t.subjectTwo
LEFT JOIN
        subjects s3
ON      s3.subjectId = t.subjectThree
WHERE   'English' IN (s1.subjectName, s2.subjectName, s3.subjectName)

or, referring to your original problem,

SELECT  t.teacherId, s1.subjectName AS name1, s2.subjectName AS name2, s3.subjectName AS name3
FROM    teacherProfile t
LEFT JOIN
        subjects s1
ON      s1.subjectId = t.subjectOne 
LEFT JOIN
        subjects s2
ON      s2.subjectId = t.subjectTwo
LEFT JOIN
        subjects s3
ON      s3.subjectId = t.subjectThree
WHERE   MATCH(s1.subjectName, s2.subjectName, s3.subjectName) AGAINST ('+English +Physics' IN BOOLEAN MODE)

(works only if both tables MyISAM)

This will return all teachers who teach both Englishand Physics.

+1
source

You cannot reference column labels you should reference the column like this:

WHERE s1.subjectName = 'ENGLISH'
+1
source

,

s1.subjectName = 'ENGLISH'

+1

Source: https://habr.com/ru/post/1768081/


All Articles