Note: these pages are no longer maintainedNever the less, much of the information is still relevant.Beware, however, that some of the command syntax is from older versions, and thus may no longer work as expected. Also: external links, from external sources, inside these pages may no longer function. |
Basics about SQL queries |
|
2011 January 28 |
Previous Slide | Table of Contents | Next Slide |
SELECT * FROM reg2001_s; |
SELECT pop2001, regione FROM reg2001_s; |
SELECT Cod_rEg AS code, REGIONE AS name, pop2001 AS "population (2001)" FROM reg2001_s; |
SELECT COD_REG, REGIONE, POP2001 FROM reg2001_s ORDER BY regione; |
SELECT COD_REG, REGIONE, POP2001 FROM reg2001_s ORDER BY POP2001 DESC; |
SELECT COD_PRO, PROVINCIA, SIGLA FROM prov2001_s WHERE COD_REG = 9; |
SELECT PRO_COM, NOME_COM, POP2001 FROM com2001_s WHERE COD_PRO = 48; |
SELECT PRO_COM, NOME_COM, POP2001 FROM com2001_s WHERE COD_REG = 9 AND POP2001 > 50000 ORDER BY POP2001 DESC; |
SELECT PRO_COM, NOME_COM, POP2001 FROM com2001_s WHERE nome_com = 'ROMA'; |
SELECT PRO_COM, NOME_COM, POP2001 FROM com2001_s WHERE nome_com = 'L''AQUILA'; |
SELECT PRO_COM, NOME_COM, POP2001 FROM com2001_s WHERE nome_com LIKE 'roma'; |
SELECT PRO_COM, NOME_COM, POP2001 FROM com2001_s WHERE nome_com LIKE '%maria%'; |
SELECT PRO_COM, NOME_COM, POP2001 FROM com2001_s WHERE nome_com IN ('ROMA', 'MILANO', 'NAPOLI'); |
SELECT PRO_COM, NOME_COM, POP2001 FROM com2001_s WHERE POP2001 BETWEEN 1990 AND 2010; |
SELECT PROVINCIA, SIGLA, POP2001 FROM prov2001_s WHERE COD_REG IN (9, 10, 11, 12) AND SIGLA NOT IN ('LI', 'PI') AND (POP2001 BETWEEN 300000 AND 500000 OR POP2001 > 750000); |
SELECT PROVINCIA, SIGLA, POP2001 FROM prov2001_s WHERE COD_REG IN (9, 10, 11, 12) AND SIGLA NOT IN ('LI', 'PI') AND POP2001 BETWEEN 300000 AND 500000 OR POP2001 > 750000; |
SELECT * FROM com2001_s LIMIT 10; |
SELECT * FROM com2001_s LIMIT 10 OFFSET 1000; |
Learning SQL isn't so difficult after all.
There are very few keywords, language syntax is notably regular and predictable, and query statements are designed to resemble plain English (as much as possible ...). Now you are supposed to be able to attempt writing (simple) SQL query statements by yourself. |
Previous Slide | Table of Contents | Next Slide |
Author: Alessandro Furieri a.furieri@lqt.it | |
This work is licensed under the Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) license. | |
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. |