Re: simple sql problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Merlin wrote:

Hello ,

I have a sql problem which seems to be simple, but I am kind of stuck,

There are 2 tables with IDs. I would like to find out which ID from table
one is not in table 2.

My statement:
SELECT ap. *
FROM pictures p , album_pictures ap
WHERE ap.pic_id != p.pic_id

returns of course all the ids from table pictures which are not in table
album_pictures, but I would like to have
it the other way arround.

So you want all IDs in album_pictures that are not in pictures?


SELECT ap.id FROM album_pictures ap LEFT JOIN pictures p ON ap.id = p.id
WHERE p.id IS NULL

The people that "need" sub-selects for things like this need to learn some more SQL... but we're getting off topic. :)

--
---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

PHP|Architect: A magazine for PHP Professionals – www.phparch.com





--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux