Home     About author     Author CV     Contact us

SQL mix

MySQL:
Count # of same value:

SELECT siteid, COUNT(siteid) AS t_site 
FROM `stats` 
GROUP BY siteid 
ORDER BY t_site DESC;

PostreSQL:
NOT IN vs. NOT EXISTS vs. LEFT JOIN / IS NULL: PostgreSQL

SELECT  l.*
FROM    t_left l LEFT JOIN t_right r
ON      r.value = l.value
WHERE   r.value IS NULL