SQL - SELECT Query

    In SQL when we want to see the data then we use the SQL SELECT command, the SELECT command work along with the FROM command and it fetch the data from the tables and return data in tabular form.

    SELECT-Syntax

    SELECT column_name_1, column_name_2, column_name_N
    FROM table_name; 

    Example

    For instance, we have a Students table:
    +------+--------+------+--------+-------+
    | id   | name   | age  | grades | marks |
    +------+--------+------+--------+-------+
    |    1 | Luffy  |   16 | A      |   970 |
    |    2 | Naruto |   18 | A      |   960 |
    |    3 | Zoro   |   20 | A      |   940 |
    |    4 | Sanji  |   21 | B      |   899 |
    |    5 | Nami   |   17 | B      |   896 |
    |    6 | Robin  | NULL | NULL   |   860 |
    +------+--------+------+--------+-------+

    Query: Use SELECT command to show the students name, grade and marks:

    SELECT name, grades, marks
    FROM students;

    Output

    +--------+--------+-------+
    | name   | grades | marks |
    +--------+--------+-------+
    | Luffy  | A      |   970 |
    | Naruto | A      |   960 |
    | Zoro   | A      |   940 |
    | Sanji  | B      |   899 |
    | Nami   | B      |   896 |
    | Robin  | NULL   |   860 |
    +--------+--------+-------+
    6 rows in set (0.00 sec)

    SELECT * Statement

    If we want to print the complete table then we can use the SELECT * command here * represent all.

    SELECT *-Syntax

    SELECT * FROM table_name;

    Example

    Query : Select the Complete table:

    SELECT * from students;

    Output

    +------+--------+------+--------+-------+
    | id   | name   | age  | grades | marks |
    +------+--------+------+--------+-------+
    |    1 | Luffy  |   16 | A      |   970 |
    |    2 | Naruto |   18 | A      |   960 |
    |    3 | Zoro   |   20 | A      |   940 |
    |    4 | Sanji  |   21 | B      |   899 |
    |    5 | Nami   |   17 | B      |   896 |
    |    6 | Robin  | NULL | NULL   |   860 |
    +------+--------+------+--------+-------+
    6 rows in set (0.00 sec)

    Summary

    • To print data from a table we use the SELECT .
    • The SELECT command work along with the FORM .
    • To select the complete table, use the * symbol along with the SELECT command.

    People are also reading: