我正在尝试执行此查询。我有这三个表项目 id 名称
authors
id
id_user
fk_id project
type = author, editor
在表中,我有作者是谁,谁是创建者,谁是编辑我试图在 mysql 中进行查询,您可以在一条记录中看到谁是作者和出版商。
我与两者之一进行咨询
SELECT p.id_project,p.name_project,a.fk_id_user,a.type,u.name
FROM projects p,users u, authors a
where p.id_project = a.fk_id_project
and a.type = 'author'
and a.fk_id_user = u.id_user
结果是
id_project, name_proyect, type, user, name_user
1 , bambo, author, 145, andrea
想做这个
id_project, name_proyect, type, user, name_user, type2, user2, name_user2
1 ,bambo , author,145, andrea, editor, 785, barack
尝试这样做但没有奏效
SELECT p.id_project,p.name_project,a.fk_id_user,a.type,u.name,a.fk_id_user as user2, a.tipo as type2
FROM
projects p, users u, authors to
where p.id_project = a.fk_id_project
and a.type = 'author'
and a.fk_id_user = u.id_user
and user2 = u.id_user
and Typo2 = 'editor'
这种类型的查询可以使用,或者如果我做错了。