WHERE vs HAVING

Why is it that you need to place columns you create yourself (for example “select 1 as number”) after HAVING and not WHERE in MySQL? WHERE is applied before GROUP BY, HAVING is applied after (and can filter on aggregates). In general, you can reference aliases in neither of these clauses, but MySQL allows referencing … Read more

How to speed up insertion performance in PostgreSQL

See populate a database in the PostgreSQL manual, depesz’s excellent-as-usual article on the topic, and this SO question. (Note that this answer is about bulk-loading data into an existing DB or to create a new one. If you’re interested DB restore performance with pg_restore or psql execution of pg_dump output, much of this doesn’t apply … Read more

SQL RANK() versus ROW_NUMBER()

You will only see the difference if you have ties within a partition for a particular ordering value. RANK and DENSE_RANK are deterministic in this case, all rows with the same value for both the ordering and partitioning columns will end up with an equal result, whereas ROW_NUMBER will arbitrarily (non deterministically) assign an incrementing … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)