[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-db
Subject:    Re: [PHP-DB] Select...
From:       OKi98 <oki98 () centrum ! cz>
Date:       2008-01-15 11:30:46
Message-ID: 478C9966.10006 () centrum ! cz
[Download RAW message or body]

-------- Original Message  --------
Subject: [PHP-DB] Select...
From: Miguel Guirao <miguel.guirao@mail.telcel.com>
To: php-db@lists.php.net
Date: 15.1.2008 4:44
> Hello List,
>
> I'm having kind of trouble to get done this: Select data from a table,
> except those data already in a second table. Actually,  if there is a rowid
> in table2, I wont get it from table1, rowid is the key that relates both
> tables.
>
> I just can't express this with a SQL statement!! idequipomed is the key that
> relates both tables!!
> So, if idequipomed is already in Table2, I shouldn't get it from Table1.
> Any suggestions?
>
>   
Many ways to do this. Choose the solution that gives you the best 
performance.

Solution 1:
SELECT t2.idequipomed
FROM table2 t2
WHERE NOT EXISTS (
    SELECT 1 FROM table1 WHERE table1.idequipomed = t2.idequipomed
    )

Solution 2:
SELECT idequipomed
FROM table2
WHERE idequipomed NOT IN (SELECT idequipomed FROM table1)

Solution 3:
SELECT table2.idequipomed
FROM table2
LEFT JOIN table1 ON table1.idequipomed = table2.idequipomed
WHERE table1.idequipomed IS NULL

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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic