connectseekers.com

Thursday, 19 March 2020

SQL Query Select Statement With Examples

3/19/2020 - By Pranav Singh 0


This article will show you how you can write and use select statement query in different ways. In this article i will cover below mention points:

1. Select all columns
2. Select Specific column
3. Select all columns with condition
4. Select specific column with where clause
5. Select statement with multiple condition
6. Select statement for removing duplicate
7. Ascending & descending order of records
8. Select top 10 values
9. Aggregate function like count, sum ,min, max, avg
10.Sub query in SQL
11.Select query Union


Please check the below table. We will perform all the query activity in this DB table.



1. Select all columns: This query will provide all the data present into the table

Select * from TestData;



2. Select Specific column: This table will help us to get specific column data from table

Select Id,Name,Address,PhoneNo from TestData



3. Select all columns with condition: This will help us to get the on the bases of the given condition

Select * from TestData Where Id=1;



4. Select specific column with where clause: This will help us to get the specific column on the bases of given conditions

Select Id,Name,Address,PhoneNo from TestData Where Id=1



5. Select statement with multiple conditions: This will tell how we can get data on the bases of multiple condition

Select Id,Name,Address,PhoneNo from TestData Where Id=1 and PhoneNo=00000000



If condition changes we will not get anything.

Select Id,Name,Address,PhoneNo from TestData Where Id=1 and PhoneNo=22222222

The above query will return no record because the condition is getting false.



6. Select statement for removing duplicate: To remove duplicate record from table

Select distinct PhoneNo from TestData

Table is having duplicate phone no.


As we execute the query it will return only distinct value.


7. Ascending & descending order of records: To display the data into ascending and descending order

Ascending:
Select * from TestData order by Id asc


 Descending:
Select * from TestData order by Id desc


8. Select top few values: To get the specific count of values

Select top 2* from TestData



9. Aggregate function like count, sum ,min, max, avg : To perform aggregate oration

Count: To count the total no of records

Select Count(*) from TestData



Sum: To get the sum of column values

Select Sum(Id) from TestData


Min: To get the minimum value of the column

Select min(Id) from TestData


Max: To get the max value of the given column no

Select max(Id) from TestData


Avg: To get the Average of the given column numbers

Select Avg(Id) from TestData



10. Sub query in SQL: This we use to get the data by creating query inside a query

Select * from TestData Where Id =(Select Id from TestData Where Id =3)


11. Select query Union: This we use to merge two tables.

Select * from TestData
Union
Select * from TestData1

Here in above query we are trying to merge the two tables.



When we execute the query we will get records as


Thanks for reading the article. Please let me know you comment.

Please subscribe my YouTube Chanel




Tags:
About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top