dbTalk Databases Forums  

get what is not equal in a.c to b.c

comp.databases.mysql comp.databases.mysql


Discuss get what is not equal in a.c to b.c in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
jrough
 
Posts: n/a

Default get what is not equal in a.c to b.c - 03-02-2011 , 10:35 AM






How come this one works
SELECT DISTINCT a.d
FROM a,b
WHERE a.c
NOT IN (SELECT b.c FROM b)

but this one doesn't
SELECT DISTINCT a.d,a.c
FROM a
LEFT JOIN b USING (c) WHERE a.c<>b.c


I'm trying to get the rows in a.c that don't match b.c but the 2nd one
should be faster.
thanks, Janis



TABLE A TABLE B

col d col c col c
____________ ____________
1 apple apple
2 banana kiwi
3 orange banana
4 grapefruit blackberry
5 cherry persimmon
6 NULL apple
thanks,

Reply With Quote
  #2  
Old   
jrough
 
Posts: n/a

Default Re: get what is not equal in a.c to b.c - 03-02-2011 , 03:16 PM






On Mar 2, 8:35*am, jrough <janis.ro... (AT) gmail (DOT) com> wrote:
Quote:
How come this one works
SELECT DISTINCT a.d
FROM a,b
WHERE a.c
NOT IN (SELECT b.c FROM b)

but this one doesn't
* * * * * * * * SELECT DISTINCT a.d,a.c
* * * * * * * * FROM a
* * * * * * * * LEFT JOIN b USING (c) WHERE a.c<>b.c

I'm trying to get the rows in a.c that don't match b.c but the 2nd one
should be faster.
thanks, Janis

TABLE A * * * * * * * TABLE B

col d * col c * * * * * *col c
____________ * * * ____________
1 * * *apple * * * *apple
2 * * *banana * * * * kiwi
3 * * *orange * * * * banana
4 * * *grapefruit * * blackberry
5 * * *cherry * * * * persimmon
6 * * NULL * * * * * * * *apple
thanks,
Please disregard, I have it.


SELECT DISTINCT a.d, a.c
FROM a
INNER JOIN b ON a.c <> b.c
WHERE a.c NOT
IN (

SELECT b.c
FROM b
)
LIMIT 0 , 30

Reply With Quote
  #3  
Old   
Doug Miller
 
Posts: n/a

Default Re: get what is not equal in a.c to b.c - 03-02-2011 , 03:33 PM



In article <e2adaaf6-b260-46e3-829c-46d060abbb43 (AT) o30g2000pra (DOT) googlegroups.com>, jrough <janis.rough (AT) gmail (DOT) com> wrote:
Quote:
Please disregard, I have it.
Whatever you have, I hope it's not contagious.

Reply With Quote
  #4  
Old   
Lennart Jonsson
 
Posts: n/a

Default Re: get what is not equal in a.c to b.c - 03-02-2011 , 05:06 PM



On 2011-03-02 22:16, jrough wrote:
[...]
Quote:
TABLE A TABLE B

col d col c col c
____________ ____________
1 apple apple
2 banana kiwi
3 orange banana
4 grapefruit blackberry
5 cherry persimmon
6 NULL apple
thanks,

Please disregard, I have it.


SELECT DISTINCT a.d, a.c
FROM a
INNER JOIN b ON a.c <> b.c
WHERE a.c NOT
IN (

SELECT b.c
FROM b
)
LIMIT 0 , 30
Not sure what it is you are trying to do, does the following give the
correct answer?

SELECT a.d, a.c
FROM a
LEFT JOIN b
USING (c)
WHERE b.c IS NULL

Another option:

SELECT a.d, a.c
FROM a
WHERE NOT EXISTS (
SELECT 1
FROM b
WHERE a.c = b.c
)

/Lennart

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.