2 table query with null

tubar

Registered User.
Local time
Today, 13:21
Joined
Jul 13, 2006
Messages
190
i have two tables linked in a query...one table is title the other is actor...i want to see what titles dont have actors but all i am getting are records that have both....how do i accomplish this
 
i am guessing something likie:
PHP:
SELECT

table.title, table2.actor

INNER JOIN etc...

WHERE [actor] IS NULL
 
better yet what would i do to build a query or code to go through all my id records in a table and list ones that are missing
 
i have two tables linked in a query...one table is title the other is actor...i want to see what titles dont have actors but all i am getting are records that have both....how do i accomplish this

AjeTrumpet gave you the general outline, but I'll fill in some of the details. He's referring to to this type of query.

SELECT * FROM Titles
LEFT JOIN Actors
ON Titles.TitleID = Actors.TitleID
WHERE Actors.TitleID IS NULL

The above is difficult to understand if you're an absolute beginner. You can rewrite this query in a way easier to understand (but it runs slow this way).

SELECT TitleID FROM Titles
WHERE TitleID NOT IN
(SELECT TitleID FROM Actors)

In both cases, this should report those titles that exist in the Titles table but do not exist in the Actors table (titles without actors). Or if you want those actors without titles:

SELECT TitleID FROM Actors
WHERE TitleID NOT IN
(SELECT TitleID FROM Titles)
 

Users who are viewing this thread

Back
Top Bottom