Re: mysql query question

John ORourke <[email protected]> Tue, 05 Feb 2008 17:04:26 +0000
Newsgroups gmane.comp.db.mysql.perl
Message-ID <[email protected]>
Not sure if this is on topic but here goes...

Kiran Annaiah wrote:
> chipid and its corresponding chip_section values (i have about 3000 of them) select * from TABLEA where chipid in('1873031558', '1887262626') and chip_section in('A','A') so the result should return only the rows which satisfy the AND condition (1st chipid with 1st chip_section) , 
You're not telling it what you think are are - you are saying:

.... where (chipid=X or chipid=Y or chipid=Z) AND (chip_section=A or 
chip_section=B or chip_section=C)

You want to say:

.... where (chipid=X and chip_section=A) OR (chipid=Y and 
chip_section=B) OR ....

My suggestion is make a temporary table with 2 columns listing chipid 
and chip_section combinations that you want, then use a left join to 
join that to the main table, and only select rows where the joined 
values are not null - that will be a lot quicker too if you have an 
index on both columns.

cheers
John


-- 
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe:    http://lists.mysql.com/[email protected]