我有3张桌子
books_table
author_table
author_compiled_relation
QUERY ITSELF:
SELECT
b.id 'id',
b.auth_id 'auther_id',
b.t_auth_id 't_auth_id',
b.unique_name 'unique_name',
b.native_name 'native_name',
a.id 'auth_id',
ar.book_id 'ar_bookid',
ar.auth_id 'ar_authid'
FROM
books b,
authors a,
authors_compile_rel ar
WHERE
b.auth_id = ".$auth_id."
OR
b.t_auth_id = ".$bq_details['t_auth_id']."
OR
ar.auth_id = ".$auth_id."
OR
b.id = ar.book_id
AND
b.status = '1'
ORDER by id DESC
上述查询无法满足我的要求:
1:books_table(id,name,author,translator) 2:author_table(id,name) 3:author_compiled_relation(作者,booksid)
我和author id
一起进入了水果表中的书。
当我查询获取作者的书籍时,它没有任何问题。
并且以其名义获得翻译书籍的工作正常。
现在我想得到由某某编写的书籍。
在author_compiled_relation
我已输入booksid
& author
。
现在我想做一个查询,所以如果作者将书籍作为作者或翻译者或作为编译器,它将在尊重的作者ID下显示书籍。
我已经制作了author_compiled_relation
表,因为编译器可以不止一个。
请帮忙......
答案 0 :(得分:0)
已经完成....我现在开始工作,答案如下:
$query = "
SELECT books.id, books.unique_name, books.native_name, books.auth_id,
books.t_auth_id, books.status, ar.auth_id, ar.book_id
FROM
books, authors_compiler_relation ar
WHERE
books.status = 1
AND
ar.auth_id = ".$auth_id."
AND
ar.book_id = books.id
OR
books.auth_id = ".$auth_id."
OR
books.t_auth_id = ".$auth_id."
ORDER by id DESC";