简体   繁体   中英

why mysql query select from two tables by " IN " is slow query

i have a two table contains customer id like this :

(SELECT * FROM customers WHERE cellular = '$cellular' OR  id  IN(SELECT customer FROM clients WHERE number=$cellular  ) )

when i search for customer cellular client OR cellular this mysql query take a 30 seconds . how i can to be more fast?

Try MySQL join

SELECT * FROM customers left join clients 
on customers.id=clients.customer 
where clients.number=$cellular or customers.cellular = '$cellular'

or try this query :-

SELECT * FROM customers inner join clients 
on customers.id=clients.customer 
where clients.number=$cellular or customers.cellular = '$cellular'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM