我正在尝试从第二个和第三个表中的列加入下面第一个表中的两个不同列。
我希望将 users.id 加入到 job_listings.id 以返回 users.username,并且还希望通过 FIND_IN_SET 将 job_listings.categories 加入并分隔到 job_categories.id 以返回 job_categories.description
job_listings
id    |  employer_id  |  categories
1     |       1       |  1,2
2     |       1       |  2
users
id    |  username  |  type
1     |    foo     |  employer
2     |    wat     |  employer
job_categories
id    |  description
1     |     fun
2     |     hak
我希望输出具有以下格式:
output
username  |    type    |  category  |  description
  foo     |  employer  |     1      |      fun
  foo     |  employer  |     2      |      hak
  foo     |  employer  |     2      |      hak
我尝试使用以下代码的各种排列:
SELECT users.username, users.type, job_listings.categories FROM users
JOIN job_listings ON users.id
JOIN job_listings AS category ON FIND_IN_SET(category.categories, job_categories.id)
ORDER BY users.username, category.categories
我从其他答案中知道我需要使用别名才能对同一个表使用多个 JOIN 操作,但是尽管调整了其他答案,但我仍然收到与声明别名相关的错误,或者返回具有别名但列的输出该列中没有返回数据。