Categories
sql

SQL: The Select Statement tutorial 1

SELECT statement falls under DQL (Data Query Language ) of SQL. It is used to query or retrieve data from sql. Here is a sample table for use to practise. The table name is trees.

+—————————————–Table————————————–+

PlotID TreeTagNumber SpeciesID DBH Height Researcher Date
110 461 5 3.00 4.00 Fernando 1999-01-01
110 462 51 19.30 25.73 Fernando 1999-01-01
110 465 76 4.10 5.46 Fernando 1999-01-01
110 466 76 4.50 6.00 Fernando 1999-01-01
110 467 76 4.40 5.86 Fernando 1999-01-01
110 468 76 9.50 12.66 Fernando 1999-01-01
110 469 76 5.30 7.06 Fernando 1999-01-01
110 470 62 7.20 9.60 Fernando 1999-01-01
110 471 62 3.40 4.53 Fernando 1999-01-01
110 472 62 7.10 9.46 Fernando 1999-01-01

+——————————————-+——————————————+

SELECT * from trees;

GENERIC SYNTAX below

SELECT * from TABLENAME

This is show all the columns and rows in table trees. If you want to see only specific columns you have to issue the sql command like this

[GENERIC FORMAT]

SELECT column1,column2 from TABLENAME

column1 & column2 are column names in the table.

SELECT PlotID,TreeTagNumber from trees;

This command displays only PlotID and TreeTagNumber from above table. The output will be like this

+————————————OUTPUT——————————————+

PlotID TreeTagNumber
110 461
110 462
110 465
110 466
110 467
110 468
110 469
110 470
110 471
110 472

+——————————————-+——————————————+