TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

SQL SELECT

SQL select query or statement with sql, tutorial, examples, insert, update, delete, select, join, database, table, join

<< Back to SQL

SQL SELECT

The most commonly used SQL command is SELECT statement. It is used to query the database and retrieve selected data that follow the conditions we want.

In simple words, we can say that the select statement used to query or retrieve data from a table in the database.

Let's see the syntax of select statement.

SELECT expressions
FROM tables
WHERE conditions;

Here expression is the column that we want to retrieve.

Tables indicate the tables, we want to retrieve records from.


Optional clauses in SELECT statement

There are some optional clauses in SELECT statement:

[WHERE Clause] : It specifies which rows to retrieve.

[GROUP BY Clause] : Groups rows that share a property so that the aggregate function can be applied to each group.

[HAVING Clause] : It selects among the groups defined by the GROUP BY clause.

[ORDER BY Clause] : It specifies an order in which to return the rows.

For example, let a database table: student_details;

IDFirst_nameLast_nameAgeSubjectHobby
1AmarSharma20MathsCricket
2AkbarKhan22BiologyFootball
3AnthonyMilton25CommerceGambling

From the above example, select the first name of all the students. To do so, query should be like this:

SELECT first_name FROM student_details;

Note: the SQL commands are not case sensitive. We can also write the above SELECT statement as:

select first_name from student_details;

Now, you will get following data:

Amar
Akbar
Anthony

We can also retrieve data from more than one column. For example, to select first name and last name of all the students, you need to write

SELECT first_name, last_name FROM student_details;

Now, you will get following data:

AmarSharma
AkbarKhan
AnthonyMilton

We can also use clauses like WHERE, GROUP BY, HAVING, ORDER BY with SELECT statement.

Here a point is notable that only SELECT and FROM statements are necessary in SQL SELECT statements. Other clauses like WHERE, GROUP BY, ORDER BY, HAVING may be optional.

Next TopicSQL SELECT UNIQUE




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf