SQL Select Statements Syntax With Order By Group By
Sql Select Statements |
SQL Select Statements
We as freshers in the field of technology aren't much aware of the syntax of a particular language, we only know the overall view about that technology. Over the time we learn and revise the technical languages and then after loads of practice we remember the exact syntax.
This post is for those who aren't much aware about SQL Select statements or are looking to brush up their SQL knowledge. In this post we will learn the basic select statements and when to use them.
- Basic Syntax
- When to use which statement
- What would be the expected output
- Different ways of writing a SELECT Statement.
Let's start with different types of SELECT statements In SQL:
- SELECT for records from Table
Select * From Customer
-Here '*' sign tells that we want the data for all the columns
- SELECT for specific column and all rows from Table
Select CustomerName From Customer
-Here 'CustomerName' tells that we want the data for only CustomerName column
- SELECT Top Rows of data from Table In SQL
Select Top 3 ContactName From Customer
-Here 'Top 3' tells that we want the top 3 rows of data for ContactName column
- SELECT with Where Clause In SQL
Select * From Customer Where CustomerID = 2
-Here 'Where CustomerID = 2' tells that we want the data for only those records which have
their CustomerID as 2.
- SELECT with Order By In SQL
Select CustomerID, CustomerName, Address From Customer Order By CustomerID desc
-Here 'Order By CustomerID desc' tells that we want the data for all records ordered by their
CustomerID in descending order. If we don't write desc(descending), the default order is
asc(ascending)
- SELECT with Distinct In SQL
Select Distinct(Country) From Customer
-Here 'Distinct(Country)' tells that we want only distinct country names in case there are
multiple Country present.
- SELECT with Group By In SQL
Select count(*) as RecordCount, Country From Customer Group By Country
-Here 'Group By Country' tells that we want to group our records by Coutry
and 'count(*) as RecordCount' tells that we want count of records grouped by Country.
So these are few queries that you can use and get the job done. You can make changes as per ur table and hopefully it will help you. So if you find it helpful or you have some problem or suggestions, do write to us.
Happy Reading!
Comments
Post a Comment
Hey there, liked our post. Let us know.
Please don't put promotional links. It doesn't look nice :)