EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

SQL SELECT Query

By Shree Ram SharmaShree Ram Sharma

Home » Data Science » Data Science Tutorials » SQL Tutorial » SQL SELECT Query

sql select query

Introduction to SQL SELECT Query

‘Select’ queries in SQL are used to fetch one or more records from a table/ database, which can also accommodate other condition clauses, depending on the user’s needs. The resulting data set is stored temporarily on an output table set, commonly known as ‘result-set. Querying with a ‘select’ statement can return a whole table if no condition statements are included or return only intended data if filters or conditions are included in the ‘select’ query.

Syntax of SQL SELECT Query

Select is one of the basic commands of the relational database management system. We can use the SELECT keyword as a prefix to select the record(s) from a given table. The select query return set of records from the given one or more tables.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

1. Selecting the required columns of a given table

SELECT <column_A>, <column_B>, ...... FROM <My_table_name>;

Explanation:

  • SELECT  is a command itself; we can use it to select the record from the table.
  • <column_A>, <column_B>, …… are the columns of the table My_table_name.
  • <My_table_name> is the name of a table.

2. Selecting all the columns of a table

SELECT * FROM <My_table_name>;

Explanation:

  • SELECT  is a command itself we can use to select the record from the table.
  • * denotes all the columns of the given table.
  • <My_table_name> is the name of a table.

3. Selecting the records with the WHERE clause

SELECT <column_One>, <column_Two>, ...... FROM <My_table > WHERE <column_ One > = <Column_Value>;

Explanation:

  • <column_One>, <column_Two>, …… are the columns of the table My_table.
  • <My_table > is the name of a table.
  • WHERE is a keyword we can use in the SQL select statement to select the specified condition records.

4. Selecting the number of records

SELECT  COUNT(*)  FROM <My_table>;

Explanation:

  • COUNT(*), this will give us the total number of rows of the table My_table.
  • <My_table > is the name of a table.

Examples of SQL SELECT Query

In this section, we will discuss some examples, considering the syntax mentioned above so that anyone can easily understand by putting in little effort. Let’s practice some examples to understand the SQL select statement better.

Suppose we have a database name “SCHOOL”. This database has tables, as mentioned below:

Students:

Student Table

Class:

Class

Example #1 – SELECT with Required Columns

Query:

SELECT Student_ID, First_name, Last_name from Student;

Output:

SQL Select Query- Column example

Query:

SELECT Student_ID, Class from Class;

Output:

column example output

Example #2 – SELECT all the Columns of a Table

Query:

SELECT * from Student;

Output:

SQL Select Query - Table example

Query:

SELECT * from Class;

Output:

Table example output

Example #3 – Selecting the Records with WHERE Clause

Query:

SELECT * from Student WHERE First_name="Alex";

Output:

SQL SELECT Query - clause example

Query:

SELECT * from Class where Medium=' English ';

Output:

clause example output

Example #4 – Selecting the Number of Records

Query:

SELECT COUN(*) as count  from Student;

Output:

Record example output

Query:

SELECT COUN(*) as count  from Class;

Output:

Output

Other Facts about the SQL SELECT

The select statement mentioned above can be performed on the relational database. There are various other select statement queries we can use to select the records. The select statement always returns a result set. This result set may contain zero (0), one, or multiple records as well. There are various other things in the select statement we can use to get the desired result. We can use the JOIN keyword to select the records from two or more tables. There are various ways to use two or more select statements to get records from one or more tables. We should use a primary key to any table so that a record can be identified uniquely.

We can use the below mentioned optional clause with the SELECT statement:

  • WHERE: We have already seen this with examples.
  • GROUP BY: This is required before using the aggregate function.
  • HAVING: We can perform an aggregate function using this over the GROUP BY statement.
  • ORDER BY: We can use this with the SELECT to sort the order of the result set.
  • AS: We have seen this while selecting the total records of a given table. This AS can be used to make an alias of either the selected column or the table.

Conclusion

We can use the SQL select statement to select the required columns or the records as per the business need. Almost every relational database has this SELECT command to select the record from the table. We can use select in various ways. We can select conditional-based records. The select operation can be performed on one or more tables. We can combine various other commands with the SELECT statements. MySQL, ORACLE are examples of relational database management system.

Recommended Articles

This is a guide to SQL SELECT Query. Here we discuss the introduction, syntax, examples and some other facts about the SQL Select Query. You may also look at the following articles to learn more –

  1. SQL Insert Query
  2. MySQL Query Commands
  3. Database in SQL​ 
  4. Table in SQL

SQL Training Program (7 Courses, 8+ Projects)

7 Online Courses

8 Hands-on Projects

73+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
SQL Tutorial
  • Queries
    • SQL Insert Query
    • SQL SELECT Query
    • SQL SELECT RANDOM
    • SQL Except Select
    • SQL Subquery
    • SQL SELECT DISTINCT
    • SQL WITH AS Statement
  • Basic
    • What is SQL
    • Careers in SQL
    • Careers in SQL Server
    • IS SQL Microsoft?
    • SQL Management Tools
    • What is SQL Developer
    • Uses of SQL
    • How to Install SQL Server
    • What is SQL Server
    • SQL Server Versions
    • SQL Case Insensitive
    • SQL Expressions
    • Database in SQL
    • SQL Data Types
    • SQL Keywords
    • Composite Key in SQL
    • SQL WAITFOR
    • SQL Constraints
    • Transactions in SQL
    • First Normal Form
    • SQL Server Data Types
    • SQL Administration
    • SQL Variables
    • SQL Enum
    • SQL GROUP BY WHERE
    • SQL ROW
    • SQL EXECUTE
    • SQL EXCLUDE
    • SQL Performance Tuning
    • SQL UUID
    • Begin SQL
    • SQL Update Join
    • Cheat sheet SQL
  • Operators
    • SQL Operators
    • SQL Arithmetic Operators
    • SQL Logical Operators
    • SQL String Operators
    • Ternary Operator in SQL
  • Commands
    • SQL Commands
    • sqlplus set commands
    • SQL Alter Command
    • SQL Commands Update
    • SQL DML Commands
    • SQL DDL Commands
    • FETCH in SQL
  • Clause
    • SQL Clauses
    • SQL IN Operator
    • SQL LIKE Clause
    • SQL NOT Operator
    • SQL Minus
    • SQL WHERE Clause
    • SQL with Clause
    • SQL HAVING Clause
    • GROUP BY clause in SQL
    • SQL GROUP BY DAY
    • ORDER BY Clause in SQL
    • SQL ORDER BY CASE
    • SQL ORDER BY DESC
    • SQL ORDER BY DATE
    • SQL ORDER BY Alphabetical
    • SQL ORDER BY Ascending
    • SQL Order by Count
    • SQL GROUP BY Month
    • SQL GROUP BY Multiple Columns
    • SQL GROUPING SETS
  • Keys
    • SQL Keys
    • Primary Key in SQL
    • Foreign Key in SQL
    • Unique Key in SQL
    • Alternate Key in SQL
    • SQL Super Key
  • Functions
    • SQL Date Function
    • SQL String Functions
    • SQL Compare String
    • Timestamp to Date in SQL
    • SQL Window Functions
    • SQL Timestamp
    • SQL TO_DATE()
    • SQL DATEADD()
    • SQL DATEDIFF()
    • SQL HOUR()
    • SQLite?functions
    • ANY in SQL
    • LIKE Query in SQL
    • SQL NOT NULL
    • SQL NOT IN
    • SQL MAX()
    • SQL MIN()
    • SQL SUM()
    • SQL COUNT
    • SQL identity
    • SQL DELETE Trigger
    • SQL Declare Variable
    • SQL Text Search
    • SQL COUNT DISTINCT
    • SQL TEXT
    • SQL Limit Order By
    • BETWEEN in SQL
    • LTRIM() in SQL
    • TOP in SQL
    • SQL Select Top
    • Merge SQL
    • SQL TRUNCATE()
    • SQL UNION
    • SQL ALL
    • SQL INTERSECT
    • SQL Alias
    • SQL Server Substring
    • CUBE in SQL
    • SQL RANK()
    • SQL MOD()
    • SQL CTE
    • SQL LAG()
    • SQL MID
    • SQL avg()
    • SQL WEEK
    • SQL DELETE
    • SQL DATEPART()
    • SQL DECODE()
    • SQL DENSE_RANK()
    • SQL NTILE()
    • SQL NULLIF()
    • SQL Stuff
    • SQL Ceiling
    • SQL EXISTS
    • SQL LEAD()
    • SQL COALESCE
    • SQL BLOB
    • SQL ROW_NUMBER
    • SQL Server Replace
    • SQL Server Permission
    • T-SQL INSERT
    • SQL Ranking Function
  • Joins
    • Join Query in SQL
    • Types of Joins in SQL
    • Types of Joins in SQL Server
    • SQL Inner Join
    • SQL Join Two Tables
    • SQL Delete Join
    • SQL Left Join
    • LEFT OUTER JOIN in SQL
    • SQL Right Join
    • SQL Cross Join
    • SQL Outer Join
    • SQL Full Join
    • SQL Self Join
    • Natural Join SQL
    • SQL Multiple Join
  • Advanced
    • SQL Formatter
    • SQL Injection Attack
    • Aggregate Functions in SQL
    • IF ELSE Statement in SQL
    • SQL CASE Statement
    • SQL While Loop
    • SQL BIGINT
    • SQL Crosstab
    • SQL Wildcard Character
    • SQLAlchemy Filter
    • SQLAlchemy create_engine
    • SQL INSTR()
    • SQL now
    • SQL synonyms
    • SQLite?export to csv
    • What is Procedure in SQL
    • Stored Procedure in SQL?
    • SQL Server Constraints
    • SQL DELETE ROW
    • Column in SQL
    • Table in SQL
    • SQL Virtual Table
    • SQL Merge Two Tables
    • SQL Table Partitioning
    • SQL Temporary Table
    • SQL Clone Table
    • SQL Rename Table
    • SQL LOCK TABLE
    • SQL Clear Table
    • SQL DESCRIBE TABLE
    • SQL Mapping
    • Cursors in SQL
    • AND in SQL
    • Wildcard in SQL
    • SQL FETCH NEXT
    • SQL Views
    • SQL Delete View
    • Triggers in SQL
    • SQL UPDATE Trigger
    • SQL AFTER UPDATE Trigger
    • SQL Update Statement
    • SQL DROP TRIGGER
    • Types of SQL Views
    • SQL Port
    • SQL Clustered Index
    • SQL COMMIT
    • Distinct Keyword in SQL
    • PARTITION BY in SQL
    • SQL Set Operators
    • SQL UNION ALL
    • Metadata in SQL
    • SQL Bulk Insert
    • Array in SQL
    • SQL REGEXP
    • JSON in SQL
    • SQL For loop
    • EXPLAIN in SQL
    • ROLLUP in SQL
    • Escape Character SQL
    • SQL Cluster
    • SQL Backup
    • SQL Pattern Matching
    • SQL Users
    • ISNULL SQL Server
    • SQL pivot
    • SQL Import CSV
    • SQL if then else
    • SQL ignore-case
    • SQL Matches
    • SQL Search String
    • SQL Column Alias
    • SQL extensions
    • SQL Substring Function
    • Charindex SQL
  • NoSQ
    • NoSQL Databases List
    • NoSQL Injection
    • NoSQL vs SQL Databases
  • Interview Questions
    • SQL Interview Questions
    • Advance SQL Interview Questions
    • SQL Joins Interview Questions
    • SQL Server Interview Questions

Related Courses

JDBC Training Course

PHP course

Windows 10 Training

SQL Course Training

PL/SQL Certification Courses

Oracle Certification Courses

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Special Offer - SQL Training Program (7 Courses, 8+ Projects) Learn More