Что делает select в sql
The SELECT Statement in SQL is used to retrieve or fetch data from a database.
We can fetch either the entire table or according to some specified rules. The data returned is stored in a result table. This result table is also called the result set. With the SELECT clause of a SELECT command statement, we specify the columns that we want to be displayed in the query result and, optionally, which column headings we prefer to see above the result table.
The select clause is the first clause and is one of the last clauses of the select statement that the database server evaluates. The reason for this is that before we can determine what to include in the final result set, we need to know all of the possible columns that could be included in the final result set.
CREATE TABLE:
Output:

To fetch any column in the table.
Syntax:
SELECT column1,column2 FROM table_name
column1 , column2: names of the fields of the table
table_name: from where we want to apply query
This query will return all the rows in the table with fields column1 and column2.
SELECT Statement in SQL
To fetch the entire table or all the fields in the table:
Syntax:
SELECT * FROM table_name;
— asterisks represent all attributes of the table
Query to fetch the fields CustomerName, LastName from the table Customer:
Output:

To fetch all the fields from the table Customer:
Output:

SELECT Statement with WHERE Clause
Suppose we want to see table values with specific conditions then Where Clause is used with select statement.
Query:
Output:

SQL SELECT Statement with GROUP BY Clause
Query:
Output:

SELECT Statement with HAVING Clause
Consider the following database for Having Clause:
Query:
Output:
SELECT Statement with ORDER BY clause in SQL
Query:
Output:

This article is contributed by Harsh Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or if you want to share more information about the topic discussed above.
SQL SELECT Statement
The SELECT statement is used to select data from a database.
The data returned is stored in a result table, called the result-set.
SELECT Syntax
Here, column1, column2, . are the field names of the table you want to select data from. If you want to select all the fields available in the table, use the following syntax:
Demo Database
Below is a selection from the «Customers» table in the Northwind sample database:
SELECT Column Example
The following SQL statement selects the «CustomerName» and «City» columns from the «Customers» table:
Example
SELECT * Example
The following SQL statement selects all the columns from the «Customers» table:
Example

COLOR PICKER


Report Error
If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
Thank You For Helping Us!
Your message has been sent to W3Schools.
Top Tutorials
Top References
Top Examples
Get Certified
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.