Select: - Select is used to fetch the data from the tables in the database. Following is the syntax for using the select statement.

Syntax: -

SELECT <Column Name> FROM <Table Name>

;



Example: -
If you want to see Teacher Name from the Teacher Table:-

Select Teacher_Name from Teacher;

The above query will fetch the names of all the teachers in the teacher table.

To fetch all the details of the teachers we will use the following query: -

Select * from Teacher;

The above query will display all the details of the teachers. Here '*' refers to all the columns.

To fetch the details of more than one column (not all the columns), we will use delimeter (,) between the column names.
For example: -

Select Teacher_Name, Qualification from Teacher; will display the Teacher Names and their qualifications.

Where Clause: - Where clause is used to fetch the data according according to the conditions given by the user with the
help of operators. The following is the syntax for using where: -

Syntax: -
SELECT <Column Name>
FROM

<Table Name>
WHERE <Condition>


Example: -

If you want to see the ID of the students who secured percentage of marks equal to 65%.

Select Student_ID from Marks where MarksPercentage = 65;

Similarly we can use the different operators with where clause: -

Select Student_ID from Marks where MarksPercentage > 65;

Select Student_ID from Marks where MarksPercentage < 65;

Select Student_ID from Marks where MarksPercentage < > 65;


Order By: - It is used to fetch the data in the given order (Ascending or Descending).
The following is the syntax for order by: -

Syntax: -
SELECT <column Name>
FROM <Table Name> [WHERE ]
ORDER BY [ASC, DESC]
Example: -

If you want to see the details of the students in ascending order according to the name.

Select * from Student order by StudentName;

In the above example we have not mentioned the type of the ordering because by default it is ascending order but for
the descending order we have to specify the order: -

Select * from Student order by StudentName Desc; will display the data in the descending order.
                    

Database Discussion

...more

Database Source Code

...more

Database Related Tutorials

...more

New Database Resources

...more

Copyright © 2013 VisualBuilder. All rights reserved