开发者

need help in mysql join query

I am working on a 开发者_JS百科website where i have three tables 1:- Book Author 2:- Book type 3:- Book relationship

My first table have following fields 
-------------------
id  Author_name
1   abc
2   xyz
------------------
Second table

id  book_type
1   Politics
2   Religious

------------------
Third table

id   book_type_id   author_id
1       1             1
2       1             2

----------------------

On my webpage when a visitor clicks on a category i am getting the book_type. Now i want to get the author name having category 1 from author name table. I think i have explained clearly. if any one can solve this issue... Thanks


select * from book_author where id in (select author_id from book_relationship where book_type_id = 'selected_category_id')


Here goes another version using only a join, given that you only have the type as a string:

SELECT A.* FROM `type` T 
LEFT JOIN `authtype` AT ON T.id=AT.authid 
LEFT JOIN `authors` A on AT.`authid`=A.`id` 
WHERE T.`type`="Religion"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜