Page 1 of 1

Select query

Posted: Sun Apr 27, 2003 2:07 pm
by minds_gifts
Hello,

I have two tables: Authors(aut_id, aut_name) and books(b_id,aut_id,b_name)

How should i write my query in oder to display the aut_name from the table aut where there are no any book names under this aut_id.

Table: Authors
-----------------
1. Taub
2. Proakis
3. Paul gray

Table: Books
---------------
1. 1. C Techniques
2. 1. Networks
3. 2. DSP

Now when i run this query, i want to show only Paul gray.

Many thanks

Posted: Sun Apr 27, 2003 5:22 pm
by []InTeR[]
I think your problem is solved with a JOIN.

Try if this helps you

Code: Select all

SELECT * FROM aut
  LEFT JOIN book ON aut.id = book.aut_id
WHERE aut.name='Paul gray'

Posted: Sun May 04, 2003 12:55 pm
by Rob the R
And if you want to generalize the query so that it lists all authors that have no books associated with them, you can do this:

Code: Select all

SELECT * FROM aut 
LEFT JOIN book ON aut.id = book.aut_id 
WHERE book.aut_id is NULL