Home Web Development SQL Server How to use Subquery in SQL Server Tutorial in Urdu

How to use Subquery in SQL Server Tutorial in Urdu

13
0

Today I have shared How to Use Subquery and SQL Subquery Example, A Subquery is a simple select statement, that returns  a single value and can be nested internal a SELECT, UPDATE INSERT, or DELETE command. It is also possible to nest a subquery inside another subquery. According to MSDN, subqueries can be nested up to 32 levels.

Subqueries are always enclosed in parenthesis and also called as inner queries, and the query containing subquery is called as outer query. The columns from a table that’s present only internal a subquery, can’t be used in the SELECT list of the outer query.

How-to-Use-Subquery-and-SQL-Subquery-Example-Tutorial

However, Subquery is used to display multiple records in a single query, if you want to use Inner Join to display multiple table record in a single query statement. These Two options very helpful for you, to display multiple records as well.

How to use SQL Select Subquery:

First of All, you need to make two tables, then you will use relationship using the foreign key.  Then insert records with two table as manual, using “Insert query”. After that, you have completed these simple process then you can use Subquery to display records as you want. Below I have included examples to make a table and display record.

Create a Table in SQL Server Queries:

create table tblproducts

(ID int primary key identity(1,1),

Name varchar(50),

Descriptions nvarchar(200))

create table tblProductsSales

(ID int primary key identity(1,1),

ProductID int foreign key references tblproducts(ID),

PricePerUnit int, QtySold int)

Insert a Record in Tables SQL Serve Query:

insert into tblProducts values

(‘LEDs’,’Sony 32 Inche Black Color’),

(‘Laptop’,’ HP Probook 4540s Silver Color’),

(‘Mobile’,’ Samsung Galax’)

insert into tblProductsSales values

(1,38000,05),

(2,45000,15),

(2,45000,10),

(2,45000,10)

SQL Subquery Example:

select Name,

(select sum(QtySold) from tblProductsSales where ProductID=tblProductsSales.ID) as QtySold

from tblProducts

However, Above I have included all queries such as Create, Insert and Display Record for use subquery. You can simply follow above process, then you will understand as well. Furthermore, I have made a video tutorial on this topic, I hope video tutorial is helpful and beneficial for everyone.

I have a tech with you step by step with SQL a subquery example, simple watch on my video tutorial and follow, I hope after watch video tutorial, you will understand as well and you can easily use subquery with different ways.

SQL Subquery Example Tutorial in Urdu

Thanks for Watch Complete video, after watch How to Use Subquery and SQL Subquery Example video, I hope you have understood as well, and you will learn it something new. Kindly, share my content on social networks, and subscribe my website social networks pages like Facebook, Google+, Twitter, YouTube and Email for post updates. If you have any question / suggestion about this topic, comment or email me after received your email or comment, I will reply with your answer maximum 24 hours. Thanks Again for a visit, Read my Complete Article and Watch my Videos. Keep touch my website, I will share very soon application like  Android Application very soon.

Subscribe My YouTube Channel For Get Updates 🙂