SQL Constructs : SELECT

 The SQL SELECT statement is used to fetch the data from a database table which returns this data in the form of a result table. It is the most used SQL statement. The basic syntax of the SELECT statement is as follows −
 SELECT column_name1, column_name2, .... column_nameN FROM table_name;
At the above column_name1, column_name2.... are the fields of a table whose values we want to fetch. And in order to fetch all the fields in a table, we are going to use following :
 SELECT * FROM table_name;
For example consider the Below table students :
 STUDENT_ID  STUDENT_NAME CITY       STATE            ZIP
 ---------- ------------ ---------- ---------------- ----------
 101         John         Boston     Massachusetts    600123
 102         Mack         Chicago    Illinois         801022
 103         Bruce        Miami      Florida          700101
 104         Jack         San Jose   California       509342
Now the below statement will fetch only Student_name, City and zip.
 SQL > SELECT student_name, City, Zip FROM students;
The result would be :
 STUDENT_NAME    CITY        ZIP
 -------------- ---------- ----------
 John           Boston     600123
 Mack           Chicago    801022
 Bruce          Miami      700101
 Jack           San Jose   509342
If we want to fetch all the fields of the students table, then we should use the following query.
 SQL > SELECT * FROM students;
The result would be :
 STUDENT_ID  STUDENT_NAME    CITY         STATE            ZIP
 ---------- --------------- ------------ ---------------- ----------
  101        John           Boston       Massachusetts    600123
  102        Mack           Chicago      Illinois         801022
  103        Bruce          Miami        Florida          700101
  104        Jack           San Jose     California       509342



Next Topic :



No comments:

Post a Comment