0

I'm getting some problems making a simple SELECT w/ LEFT JOIN query:

SELECT 
   a.sttgs_id, a.sttgs_description, 
   (c.uss_id IS NOT NULL) as has 
FROM 
   (mt_user b, mt_settings a 
       LEFT JOIN mt_user_settings c 
             ON c.sttgs_id=a.sttgs_id AND 
             b.usr_id=c.usr_id
   )
WHERE  c.usr_id=2

PHPMyAdmin says: #1054 - Unknown column 'b.usr_id' in 'on clause'.

I really don't know other way to do the SELECT.

Greetings.

Edit: show create table mt_user

enter image description here

6
  • What are the fields in mt_user? Commented Mar 21, 2014 at 14:43
  • Remove the parentheses under FROM Commented Mar 21, 2014 at 14:44
  • mt_user has: usr_id, usr_login, usr_passwd, usr_firstname, etc... Commented Mar 21, 2014 at 14:44
  • Can you post the results of show create table mt_user Commented Mar 21, 2014 at 14:46
  • Do not mix implicit (comma-) and explicit JOIN syntax. In fact. Don't use implicit join syntax at all Commented Mar 21, 2014 at 14:47

1 Answer 1

1

Try this

SELECT 
      a.sttgs_id, 
      a.sttgs_description, 
      c.uss_id  as has 
FROM mt_user b 
LEFT JOIN mt_user_settings c on b.usr_id=c.usr_id
LEFT JOIN  mt_settings a ON c.sttgs_id=a.sttgs_id  --you may need INNER JOIN here
WHERE  c.usr_id=2
AND c.uss_id IS NOT NULL
Sign up to request clarification or add additional context in comments.

1 Comment

Well, It didn't solve my problem. But i created another post to specify why i want to do this: stackoverflow.com/questions/22562855/… . Thank you for answer.

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.