Home › Database

SQL & Database Tutorials

SQL queries, self joins, aggregations, H2 troubleshooting, and JPA/Hibernate with Spring Boot — practical guides for Java devs.

Advertisement

Quick SQL Reference

Query TypeUse CaseExample
SELF JOINHierarchical data (manager-employee)FROM emp e1 JOIN emp e2 ON e1.mgr=e2.id
GROUP BY + HAVINGFilter aggregated resultsGROUP BY dept HAVING COUNT(*)>5
Consecutive RowsN-row aggregationROW_NUMBER() OVER (ORDER BY id)
Delete DuplicatesKeep unique rowsDELETE WHERE id NOT IN (SELECT MIN(id)...)
Dynamic PivotRows to columnsGROUP_CONCAT / STRING_AGG

Ready

Free, no login required.

Browse All SQL Posts →