Quote:
if l choose "outer join" , the result is not what l want , it will alway return ALL books for me whether l fill in either publisherName or authorName and leave bookTitle blank ...
no no ... this is my mistake .... it is not true that it will return ALL books.
Let's try a simple example , here are my tables ,
Code:
authors link_b_a books publishers
------- --------- ------- -----------
author_id(pk) author_id(pk) book_id(pk)
author_name book_id(pk) title publisher_name
publisher_id(fk) publisher_id(pk)
----------------------- with data below ---------------------------------
1 author1 1 1 1 book1 1 1 publisher1
2 author2 1 2 2 book2 1 2 publisher2
3 author3 2 1 3 book3 2 3 publisher3
2 2 4 book4 null
3 2
this is outer join :
Quote:
SELECT * FROM books b
left outer join link_b_a ba on b.book_id=ba.book_id
left outer join authors a on ba.author_id=a.author_id
it return :
Quote:
"BOOK_ID","TITLE","PUBLISHER_ID","BOOK_ID","AUTHOR_ID","AUTHOR_ID","AUTHOR_NAME"
1,"book1",1,1,1,1,"author1"
1,"book1",1,1,2,2,"author2"
2,"book2",1,2,1,1,"author1"
2,"book2",1,2,2,2,"author2"
2,"book2",1,2,3,3,"author3"
3,"book3",2,,,,""
4,"book4",,,,,""
this is inner join :
Quote:
SELECT * FROM books b
inner join link_b_a ba on b.book_id=ba.book_id
inner join authors a on ba.author_id=a.author_id
it return:
Quote:
"BOOK_ID","TITLE","PUBLISHER_ID","BOOK_ID","AUTHOR_ID","AUTHOR_ID","AUTHOR_NAME"
1,"book1",1,1,1,1,"author1"
2,"book2",1,2,1,1,"author1"
1,"book1",1,1,2,2,"author2"
2,"book2",1,2,2,2,"author2"
2,"book2",1,2,3,3,"author3"
The above simple example showing that l "do" know the different between inner join and outer join , : ) .. hihi
.... to be continue
moon