DQL - Data Query Language : SELECT Statement

     SELECT statement is used to retrieve data from one or more table or database. We can also use it to access some specific records from the database.

Syntax: 

     SELECT col1, col2, ... FROM table_name;

It will select all of the data stored inside the table table_name;

To select some specific record, we can use where clause as

Syntax: 

    SELECT col1, col2, ... FROM table_name where condition;


Instead of specifying column names, you can use asterisk(*) sign to select all columns at once.

     SELECT * FROM table_name;


Example:

        CREATE TABLE Employee(
                    emp_id INT NOT NULL PRIMARY KEY,
                    emp_name VARCHAR(20),
                    dept VARCHAR(20),
                    salary FLOAT
       );


       INSERT INTO Employee (emp_id, emp_name, dept, salary) VALUES (1, "Joey", "CSE", 23000.00), (2, "Ross", "CE", 30000.0),(3, "Rachel", "ME", 25000.00);

      SELECT * FROM Employee;

      --To select only name and salary 

      SELECT emp_name, salary FROM Employee;

      --To select all employees whose salary is greater or equal to 25000

      SELECT * FROM Employee WHETE salary>=25000;


Continue Learning : SQL Clause 



Comments

Popular Posts