Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

very confusing query !

Status
Not open for further replies.

tom22london

Programmer
Mar 11, 2003
11
0
0
US
how can i find title of book whcih have the same publisher 'tom', but i am not supposed to include 'tom' in my output.

following are the tables,

Borrower (bor_id, bor_name, bor_maxbooks)

Book_title (bt_id, bt_name,pub_id, value)

Book_copy (bc_id, bt_id*, date acquired)

Loan (bor_id, bc_id, date_out, date_due, date_back)

Publisher (pub_id, pub_name, pub_address)

Author (author_id, author_name)

Authorship (author_id, bt_id)

--------------------------------------------
 
Is 'tom' a publisher name? If so:

Code:
SELECT bt_name
FROM book_title b JOIN publisher p ON b.pub_id = p.pub_id
WHERE pub_name = 'tom'
--James
 
i have solved that query by myself so this was the answer,

select bt_name from book_title bt1 where pub_id in(select pub_id from publisher where pub_id in(select pub_id from book_title bt2 where bt2.bt_name='tom')) and bt_name <> 'tom';
 
James' query is much more efficient but the thing is that error is coming in it. so if u can answer the query in an efficient manner than i will be thankful to u.
 
It looks like I was wrong in my assumption that 'tom' was a publisher - it is actually the name of a book and you want all other books that had the same publisher? This query should do that:

Code:
SELECT bt_name
FROM book_title bt1
WHERE pub_id = (
  SELECT pub_id
  FROM book_title
  WHERE bt_name = 'tom'
  )
  AND bt_name <> 'tom'
--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top