[nycphp-talk] Still Mysql Selects
Dan Cech
dcech at phpwerx.net
Wed Jun 22 07:42:06 EDT 2005
Alberto dos Santos wrote:
> I have a table called "CATALOG_READING" with two entries, one is the ID
> (CR_ID) and the other a value.
> Then I have 16 tables each with 4 rows that have a value from CR_ID, in
> order to use the values from the CATALOG_READING table in different
> situations.
>
> What I need to check is which values from CR_ID are NOT USED in any of the
> other tables, so I can identify and remove it.
SELECT c.cr_id
FROM catalog_reading AS c
LEFT JOIN table_x AS x ON x.cr_id=c.cr_id
LEFT JOIN table_y AS y ON y.cr_id=c.cr_id
LEFT JOIN table_z AS z ON z.cr_id=c.cr_id
...
WHERE x.cr_id IS NULL
AND y.cr_id IS NULL
AND z.cr_id IS NULL
...
Give something like that a shot.
Dan
More information about the talk
mailing list