简体   繁体   中英

DISTINCT clause in main query and subquery

Below is my query :

SELECT DISTINCT(di.device_token) FROM device_info di WHERE di.IMEI_number IN (SELECT DISTINCT(ud.device_id) FROM user_details ud WHERE ud.device_OS='android')

This query takes hell lot of time to execute because of the IN clause. I found using joins is the best way. Yet, I am unable to figure how to use DISTINCT on both the tables.

Any suggestion is welcome.

Try the below query -

SELECT distinct (di.device_token) FROM device_info di,user_details
where di.IMEI_number in (user_details.ud.device_id)
and ud.device_OS='android';

Try this:

SELECT di.device_token FROM device_info di 
JOIN user_details ON user_details.ud.device_id = di.IMEI_number
WHERE ud.device_OS='android'
GROUP BY di.device_token

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