i had a large databse and had to chec if a email is in a special group
I had to tables.
first tabel called user
CREATE TABLE user (
uid int(10) NOT NULL AUTO_INCREMENT,
kid int(3) NOT NULL,
Email varchar(255) DEFAULT NULL,
PRIMARY KEY (uid),
KEY kid (kid)
) ENGINE=MyISAM
and a table named group
CREATE TABLE `group` (
`vuid` int(10) NOT NULL AUTO_INCREMENT,
`uid` int(3) NOT NULL,
`vid` int(3) NOT NULL,
PRIMARY KEY (`vuid`)
) ENGINE=MyISAM
and for every insert i had a defined vid and a email
Now i had to check, if a user with the uid is in the group vid.
select a.email,b.vuid from user a, group b where a.email=\''.$email.'\' and a.kid=' . $kid.' and b.vid=' . $vid . ' and a.uid = b.uid limit 1')
and check if the mysql_fetch_assoc is true or false.
BUT this is verry verry slow. is there a simple way to speed up ?
Rather than using a comma separated list of tables, try using a
JOIN(in this case,INNER JOINis your best bet since you want to check if records exist in both tables) with anONclause. I have formatted your query and my changes are in capitals to make them stand out.Next, check your indexes – make sure you have indexes on b.uid and a.kid. As a general rule, check your where clauses for values you can index; anything with unique values is a candidate.