I'm looking for faster way to run this kind of statment:
SELECT *
FROM `aukcje_przedmioty`
WHERE (
(
opis NOT
IN (
SELECT opis
FROM aukcje_przedmioty
WHERE ( aktywne =1 AND user_id =6 )
)
)
AND aktywne =0
AND user_id =6
)
table aukcje_przedmioty
you can try something like
SELECT a.*
FROM `aukcje_przedmioty` a
JOIN
(
SELECT opis,user_id
FROM aukcje_przedmioty
GROUP BY opis,user_id
HAVING max(aktywne) = 0
) x
ON
x.user_id = a.user_id and
x.opis = a.opis
WHERE user_id = 6
http://sqlfiddle.com/#!2/16774/6
Use explain on your setup to see what would work best for you.
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.