Page 260 - PYTHON-12
P. 260
The above command displays all the rows of all the columns according to the column-list defined
in the table structure. The salient features of SQL SELECT statement are as follows:
SELECT command displays the columns of the table in the same order in which they are selected
from the table.
In order to retrieve all the columns in the column-list from a table using SELECT command,
asterisk (*) is used and the columns are displayed in the same order in which they are stored in
the table.
All the statements (inclusive of SELECT statement) in SQL are terminated with a semicolon (;).
Use of semicolon is dependent on the version in use.
Using WHERE clause
SELECT * FROM student WHERE Rollno<=8;
The above command shall display only those records whose Rollno is less than or equal to 8.
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
8. Akshay Dureja M 90 05-May-1997 NULL
8 rows in a set (0.02 sec)
When a WHERE clause is used with a SELECT statement, the SQL query processor goes through
the entire table one row/record at a time and checks each row to determine whether the condition
specified is true with respect to that row or not. If it evaluates to True, the corresponding row is
selected, retrieved and displayed, else it returns an empty set (i.e., no data found).
CTM: SQL is case-insensitive, which means keywords like SELECT and select have same meaning in SQL
statements. On the contrary, MySQL makes difference in table names. So, if you are working with MySQL,
then you need to give table names as they exist in the database.
3. Recording Columns while Displaying Query Results
While displaying the result for a query, the order of the columns to be displayed can be changed
according to the user’s requirement. But this is done only for the display purpose and no actual
Computer Science with Python–XII 12.30 SELECT Name, Rollno, DOB, Marks from student;
(physical) rearrangement of the columns is done.
For example,
After executing the above statement, the column shall be displayed in the changed order as Name
shall be displayed as the first column, Rollno as the second column, DOB as the third column and
Marks as the fourth column respectively.