x

SQL – SELECT

Prev     Next

  • The SELECT query/statement in SQL is used to select the data from database.
  • Either we can select all columns from a table or can select only particular column using select statement in SQL.
  • All selected data are stored in a result table which is also called as a result set. Syntax for SQL select statement is given below.

Syntax for SQL SELECT query/statement:

Syntax to select all columns SELECT * FROM table_name;
Syntax to select only selected columns SELECT column_name1, column_name2, etc FROM table_name;

Note: * is a wild card which selects all columns from a table. And, semicolon is used at the end of SQL statement to separate when more than one SQL statements are executed at the same time.


Examples of how to use SQL select query/statement:

Please consider the following table with few records as given below.

Table name (for example): student
Column names in this table: Student_ID, Student_name, City and Age
Available records: 4 rows


sql-table1

  • To select all columns from this table, please execute below query. This query will fetch all records available in this table:

SQL Query: SELECT * from student;

SQL query Output:

sql-table2

  • To select particular columns only from this table, please execute below queries:

SQL Query: SELECT Student_name, City from student;

SQL query Output:

sql-table3

SQL Query: SELECT City, age from student;

SQL query Output:

sql-table4

Prev     Next



Like it? Please Spread the word!