Re: SQL Queries

From: Date: Sun, 20 Dec 2009 21:41:45 +0000
Subject: Re: SQL Queries
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-300618@lists.php.net to get a copy of this message
Sorry for the double-post, forgot to add up the way I thought about using: Simple sql query: SELECT * FROM users as u WHERE (SELECT COUNT(id) FROM notes WHERE user_id = u.id LIMIT 0,1) = 0 Problem is I have about 450,000 "users" and about 90% don't have "notes", and it takes LOADS of times even with I limit it: SELECT * FROM users as u WHERE (SELECT COUNT(id) FROM notes WHERE user_id = u.id LIMIT 0,1) = 0 LIMIT 0,10 Takes about 10 seconds which is too much time... Any way to optimize it? On Sun, Dec 20, 2009 at 11:30 PM, דניאל דנון <danondaniel@gmail.com> wrote: > Hey, Lets assume I got a table named "users". > It contains id & name. > > I have another table called "notes" - which contains id, user_id, contents > > > I want to delete all users from table "users" that don't have notes (SELECT > ... FROM notes WHERE user_id=ID) returns empty result. > > > What is the fastest way to do it? > > -- > Use ROT26 for best security > -- Use ROT26 for best security

« previous php.general (#300618) next »