Page 259 - PYTHON-12
P. 259
12.14.1 SQL SELECT Statement
This command can perform selection as well as projection. It is the most extensively used SQL
command. The SELECT statement can be used to retrieve a subset of rows or columns from one or
more tables present in a database.
1. Selection
This capability of SQL returns the tuples from a relation with all the attributes.
Syntax:
SELECT <column-name1> [, <column-name2>…]
FROM <table-name>;
OR SELECT <what_to_select> FROM
<which_table>
WHERE <conditions_to_satisfy>;
For example,
SELECT Name, Gender FROM student;
The above command displays only name and gender attributes from the student table.
2. Projection: Selecting Specific Rows—WHERE Clause
This is the capability of SQL to return only specific attributes from the relation. Use of WHERE
clause is required when specific tuples are to be fetched or manipulated. To select all the columns
from a table, the asterisk (*) can be used.
For example,
SELECT * FROM student;
The above command will display all the tuples (rows) from the relation student.
CTM: The asterisk (*) means “All”. SELECT * means displaying all the columns from a relation.
Resultant table: student
Rollno Name Gender Marks DOB Mobile_no
1. Raj Kumar M 93 17-Nov-2000 NULL
2. Deep Singh M 98 22-Aug-1996 NULL
3. Ankit Sharma M 76 02-Feb-2000 NULL
4. Radhika Gupta F 78 03-Dec-1999 NULL
5. Payal Goel F 82 21-April-1998 NULL
6. Diksha Sharma F 80 17-Dec-1999 NULL
7. Gurpreet Kaur F 65 04-Jan-2000 NULL
Relational Database and SQL
8. Akshay Dureja M 90 05-May-1997 NULL
9. Shreya Anand F 70 08-Oct-1999 NULL
10. Prateek Mittal M 75 25-Dec-2000 NULL
10 rows in a set (0.02 sec)
12.29