Geodin Geodin - 4 months ago 7
MySQL Question

MySQL SELECT syntax error not seeing

Trying a simple query in mysql and getting syntax error that I need help seeing.

SELECT
eea.*,
ee.description,
eect.title,
eect.file,
eect.location,
eect.img_location
FROM
`e_exam` ee,
`e_exam_attempt` eea,
`e_exam_cert_template` eect
WHERE
eea.a_user_id = 1,
eea.ee_id = ee.id,
ee.eect_id = eect.id;


Getting error:(see this image)

picture of error from my vm

Basically syntax error on line 13 eea.ee_id = ee.id, ee.eect_id = eect.id LIMIT 0, 25

Answer

Its a simple syntax error, your WHERE clause should not be seperated by commas. Use AND or OR etc

SELECT 
    eea.*, ee.description, eect.title, eect.file,
    eect.location,eect.img_location
FROM 
    `e_exam` ee,
    `e_exam_attempt` eea,
    `e_exam_cert_template` eect
WHERE 
    eea.a_user_id = 1 AND
    eea.ee_id = ee.id AND
    ee.eect_id = eect.id
LIMIT 0,25

You should also learn about the JOIN syntax

SELECT 
    eea.*, ee.description, eect.title,eect.file,
    eect.location, eect.img_location
FROM `e_exam_attempt` eea
    JOIN `e_exam` ee ON eea.ee_id = ee.id
    JOIN `e_exam_cert_template` eect ON ee.eect_id = eect.id
WHERE 
    eea.a_user_id = 1 
LIMIT 0,25
Comments