我在尝试什么:
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
输出将是:
path photo | John | 31
但是我需要这样的东西(职业在另一张桌子里)
path photo | John | 31 | designer
表格
<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
有什么想法吗?
答案 0 :(得分:2)
添加了以下联接和专业选择列表。
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