1

Here is my database structure

https://docs.google.com/open?id=0B9ExyO6ktYcOenZ1WlBwdlY2R3c

My SQL query looks like that

SELECT
    u.fullname,
    a.id,
    a.content,
    a.addDT,
    a.`right`,
    acr.score,
    acr.checkDT
FROM
    answers a,
    users u
LEFT JOIN `answer_chk_results` acr ON acr.aid = a.id
WHERE
    a.qid = 7
AND u.id = a.uid
GROUP BY
    a.`right` DESC

Getting error message

[Err] 1054 - Unknown column 'a.id' in 'on clause'

I'm pretty sure that a.id column exists

What am I missing?

0

1 Answer 1

1

you can't mix join syntax with comma delimited table syntax. If you are going to left join, you need to use an inner join for the other two tables.

SELECT
    u.fullname,
    a.id,
    a.content,
    a.addDT,
    a.`right`,
    acr.score,
    acr.checkDT
FROM
    answers a
    INNER JOIN users u ON u.id = a.uid
LEFT JOIN `answer_chk_results` acr ON acr.aid = a.id
WHERE
    a.qid = 7
GROUP BY
    a.`right` DESC

This might work also, but is not guranteed:

SELECT
    u.fullname,
    a.id,
    a.content,
    a.addDT,
    a.`right`,
    acr.score,
    acr.checkDT
FROM
    (answers a,
    users u)
LEFT JOIN `answer_chk_results` acr ON acr.aid = a.id
WHERE
    a.qid = 7
AND u.id = a.uid
GROUP BY
    a.`right` DESC
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.