tags:

views:

137

answers:

2
table name:id
col1:owner-name
col2:book-id1
col3:book-id2

table name:book-name
col1:id
col2:name

Can anyone get me a query to get following result owner-name,book1-name,book2-name using above 2 table

+2  A: 
SELECT id.owner-name, b1.name "book1-name", b2.name "book2-name"
FROM id
LEFT JOIN book-name "b1" ON b1.id = id.book-id1
LEFT JOIN book-name "b2" ON b2.id = id.book-id2
Chad Birch
thanks,solves my problem
yesraaj
Well, then you should mark this answer as accepted.
Tim Büthe
yes I will.Waiting for others to up vote and for more answers
yesraaj
A: 
SELECT a.OWNER-NAME,b1.name book1,b2.name book2
FROM ID a,BOOK-NAME b1,BOOK-NAME b2
where a.book-id1= b1.id
and a.book-id2= b2.id

OR

SELECT a.OWNER-NAME,
(SELECT b1.name from BOOK-NAME b1 where b1.id=a.book-id1) BOOK_NAME1,
(SELECT b2.name from BOOK-NAME b2 where b2.id=a.book-id2) BOOK_NAME2
FROM ID a
Franklin