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.
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;
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;
Now show only the name fields, sorted by name:
SELECT name FROM EMPLOYEE ORDER BY name;
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.