Re: Join question

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

 



On Thu, 2007-11-29 at 15:41 -0500, tedd wrote:
> Hi gang:
> 
> I'm trying to understand joins,
> 
> Here's the situation. I have two tables (user1, user2) in one database:
> 
> The common field between the two tables is "username". I want to take 
> fields "login" and "password" from user2 and populate the same fields 
> in user1.
> 
> Currently, the table user1 has 5303 entries, whereas user2 has 5909.
> 
> What I want at the end of this is for table user1 to have the same 
> number of entries as table user2.
> 
> Now, how do I set up the query?

INSERT INTO table1
(
    login,
    password
)
SELECT
    T2.login,
    T2.password
FROM
    table2 AS T2
        LEFT JOIN table1 as T1 ON
            T1.login = T2.login
WHERE
    T1.login IS NULL;

That should do it... off the top of my head :)

Cheers,
Rob.
-- 
...........................................................
SwarmBuy.com - http://www.swarmbuy.com

    Leveraging the buying power of the masses!
...........................................................

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux