What is SELECT statement in MySQL

SELECT Statement in MySQL

SELECT selects records from the table. When this command is executed from the command line, MYSQL prints all the records that match the query. So, in this article, we will see SELECT Statement in MySQL.

Ex:

REATE TABLE EMPLOYEE (
  empId INTEGER PRIMARY KEY,
  name TEXT NOT NULL,
  dept TEXT NOT NULL
);

-- insert
INSERT INTO EMPLOYEE VALUES (0001, 'Clark', 'Sales'),
(0002, 'Dave', 'Accounting'),
 (0003, 'Ava', 'Sales');

Here, we have created a table called EMPLOYEE and inside it we have created data called empID an Integer datatype, name, and dept as text datatype. To display all data from a table, we need to use the above SELECT statement code.

SELECT * FROM age_infromation;

Output:

SELECT statement in MySQL

The * means “show values for all fields in the table”, and FROM specifies the table from which to extract the information. There are many ways to use the SELECT command– it’s very flexible. First, sort the table based on the name.

SELECT * FROM EMPLOYEE ORDER BY name;

Output:

SELECT * FROM EMPLOYEE ORDER BY name;

Now show only the name fields, sorted by name:

SELECT name FROM EMPLOYEE ORDER BY name;

Output:

SELECT name FROM EMPLOYEE ORDER BY name;

Conclusion

So, the SELECT statement is used to select a record. If we select we can do anything like print, delete, or modify.  If we select the data using * it will select all the records from the table.  We saw the example of SELECT comment so, I hope you all have understood this comment clearly. If you have any doubt, you can comment me in below.

READ ALSO  Numeric Data Types in MySQL | Explained

Leave a Reply