NYCPHP Meetup

NYPHP.org

[nycphp-talk] simple mysql query help

Jim Hendricks jim at bizcomputinginc.com
Tue Aug 6 12:07:11 EDT 2002


The solution I provided may not work with mysql, I'm not sure if mysql
supports nested queries.

Another way to try it would be:

SELECT aaa.* FROM aaa LEFT JOIN bbb ON aaa.ID=bbb.ID WHERE bbb.somefield IS
NULL ;

somefield would need to be any field from bbb.

Item B in your original query is based on your where clause.  With the info
you provided you get:

aaa.1 != bbb.1 ? No
aaa.1 != bbb.3 ? Yes
aaa.2 != bbb.1 ? Yes
aaa.2 != bbb.3 ? Yes

This is because you do not provide a Join condition.  Under a no join query,
you get a join that links all
records in aaa with all records in bbb which means without your where
clause, your query would result in 4 rows.


----- Original Message -----
From: "cesar" <can at andrew.cmu.edu>
To: "NYPHP Talk" <talk at nyphp.org>
Sent: Tuesday, August 06, 2002 11:54 AM
Subject: Re: [nycphp-talk] simple mysql query help


> i've attempted but solutions, neither seem to work.
>
> i'm upgrading the mysql from 3.23.44 to 3.23.51... hopefully that will do
> it.
>
> On Tue, 6 Aug 2002, Michael Southwell wrote:
>
> > how about this (haven't tested it)?  select aaa.*,bbb.* from aaa,bbb
where
> > aaa.a!=bbb.a and bbb.a!=aaa.a;
> >
> > At 11:16 AM 8/6/2002, you wrote:
> >
> > >i have two tables aaa and bbb
> > >aaa has {1 , 2}
> > >bbb has {1 , 3 }
> > >
> > >i want select those values in aaa that don't appear in bbb, and also
> > >another query that will delete those values in aaa which don't appear
in
> > >bbb. if someone can please help me, i'm just a little stuck. i know i
> > >figured it out before, but right now i have no clue.
> > >
> > >  A)
> > >mysql> select * from aaa;
> > >+------+
> > >| a    |
> > >+------+
> > >|    1 |
> > >|    2 |
> > >+------+
> > >
> > >mysql> select * from bbb;
> > >+------+
> > >| a    |
> > >+------+
> > >|    1 |
> > >|    3 |
> > >+------+
> > >
> > >B)i understand why this does what it does, but how do i correct it?
> > >mysql> select aaa.*, bbb.* from aaa, bbb where aaa.a != bbb.a;
> > >+------+------+
> > >| a    | a    |
> > >+------+------+
> > >|    2 |    1 |
> > >|    1 |    3 |
> > >|    2 |    3 |
> > >+------+------+
> > >
> > >thnka you in advance.
> >
> > Michael G. Southwell =================================
> > DNEBA Enterprises
> > 81 South Road
> > Bloomingdale, NJ 07403-1419
> > 973/492-7873 (voice and fax)
> > southwell at dneba.com
> > http://www.dneba.com
> > ======================================================
> >
> >
> >
> >
> >
>
>
>
>
>





More information about the talk mailing list