0

what i am trying:

SELECT 
`update_photo`, 
(SELECT substring_index (`username`, ' ', 1)), 
`id_user`
FROM users 

JOIN worker_has_profession
ON worker_has_profession.worker_single_user_users_id_user  = users.id_user

ORDER BY `registration` 
DESC LIMIT 10

The output will be:

path photo | John | 31

but i need something like this (profession is in another table)

path photo | John | 31 | designer

Tables

   <table worker_has_profession>
    worker_single_user_users_id_user //same id of id_user
    profession_id_profession 

      worker_single_user_users_id_user            profession_id_profession 
                    31                                      10


   <table profession>
    id_profession 
    profession

     id_profession               profession 
           10                      designer

Any idea?

3
  • So why don't you select necessary field then? Commented Jun 23, 2011 at 2:12
  • how? the field that i need is in another table Commented Jun 23, 2011 at 2:15
  • you have already added one join, so add another one. Commented Jun 23, 2011 at 2:30

1 Answer 1

2

Added the join below and profession to select list.

SELECT 
update_photo, 
(SELECT substring_index (`username`, ' ', 1)), 
U.id_user,
P.profession
FROM users U

JOIN worker_has_profession WP
ON WP.worker_single_user_users_id_user  = U.id_user

JOIN profession P
ON P.id_profession =  WP.profession_id_profession
ORDER BY registration
DESC LIMIT 10
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.