SQL Select Statement

The Select statement is used to select or fetch data from the database table.The data return from the database table as the result table is also known as the result-set.

SELECT Syntax :

The syntax of the SELECT statement is −

    SELECT column1, column2, column3, columnN FROM table-name;
   

column1 , column2, column3: names of the fields of the table table-name: table where we want to fetch data

If we want to select all the columns from the respective table then we use the following syntax:

      SELECT * FROM table-name;
    



SELECT Example :

Consider the Customer table with the following records -

CustomerID CustomerName Age Address CustomerSalary
1 Aarav 28 Bangalore 28000
2 Vivaan 25 Mumbai 30000
3 Reyansh 30 Chennai 35000
4 Muhammad 24 Udaipur 50000
5 Sai 30 Indore 27000


Test Case:-The following code is an example, which would fetch the CustomerName and Address fields of the Customer available in Customer table.

    SELECT CustomerName, Address FROM Customer;
   


The result for the respective sql query is as follows −

CustomerName Address
Aarav Bangalore
Vivaan Mumbai
Reyansh Chennai
Muhammad Udaipur
Sai Indore

Exercise:-

1. Which of the following statements contains an error?

A. Select * from emp where empid = 10003;
B. Select empid from emp where empid = 10006;
C. Select empid from emp;
D. Select empid where empid = 1009 and lastname = ‘GELLER’;

View Answer


2. Which of the following statements does not contains an error?

A. Select where empid = 10003;
B. Select empid from emp where empid = 10006;
C. Select empid from emp
D. Select empid where empid = 1009 and lastname = ‘GELLER’;

View Answer







Visit :


Discussion


* You must be logged in to add comment.