Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Illogical 1

Status
Not open for further replies.

DarkConsultant

Programmer
Dec 4, 2007
156
GB
Hi,

I have two tables, one contains contact information (count = 4500 records) and has a Primary Key of UIN. The other is a members table containing contacts' UIN's (count = 2000 records).

I needed to get all the UINs from the contacts table where the same UIN is NOT in the members table so ...

The quickest query was "SELECT UIN FROM contact WHERE UIN NOT IN (SELECT DISTINCT MemberUIN FROM members)" with a response time of .. wait for it .. 12 seconds.

So then I tried removing the subquery and creating the 'IN' part myself ...

$temp=array();
while($row=mysql_fetch_array($temp,MYSQL_ASSOC)){$x[]=$row['MemberUIN'];}

New query -
"SELECT UIN FROM contact WHERE UIN NOT IN (".implode(",",$x)")";

Response time .. wait for it .. less than .2 seconds (cant measure smaller).

Am I doing something very wrong here?

TIA

David


DarkConsultant

Live long and prosper \\//
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top