For example, in case of “IN”, one can use the subquery to get the multiple values in the IN clause or we can have predefined values.
In this article, we are going to use the following table for some examples:-
CREATE TABLE [dbo]. [Employee](
[Empid] [Int] IDENTITY (1, 1) NOT NULL Primary key,
[EmpNumber] [nvarchar](50) NOT NULL,
[EmpFirstName] [nvarchar](150) NOT NULL,
[EmpLAStName] [nvarchar](150) NULL,
[EmpEmail] [nvarchar](150) NULL,
[Salary] [int] NULL
)
Suppose, we have another table Empprojects, which contains the employees and their project relationship and it has the below table structure
create table Empprojects (empprojectid int identity(1,1), empnumber nvarchar (50), projectcode nvarchar(50))
Now suppose we want to get the records for the employees which are associated with the project having code “Proj002” or “Proj005”, then we can use the following query:-
select * from employee where empnumber in (select empnumber from Empprojects where projectcode=’Proj002′ or projectcode=’Proj005′)
In the above query, we use the subquery “select empnumber from Empprojects where projectcode=’Proj002′ or projectcode=’Proj005′ ” to fetch the multiple values in the IN clause.
Also suppose, we want to get the records of employee who worked in the first project having code ‘Proj001’. We can use subquery for it as we see in the above example. But we know that that project is completed years back and only 3 employees having empnumber “A001” , “A002” and “A003” worked on it , then we can pass the empnumber of these 3 employee as predefined values in the IN clause as shown in the below query:-
select * from employee where empnumber In (‘A001′,’A002′,’A003’)
Pingback: Jerome Powell Speech Today Stock Market Economy Gold Silver
Pingback: TorSearch onion
Pingback: w88 thailand
Pingback: vao fun88
Pingback: ฟุตบอลไทย
Pingback: http://cena-pozycjonowania.pl/bezpieczenstwo-wewnetrzne-polski-w-latach-1989-2013-wybrane-aspekty-1107.php
Pingback: w88ok
Pingback: havaianas
Pingback: Sexy Baccarat
Pingback: hair removal for men
Pingback: Accountant in Pensacola Florida
Pingback: dang ky tai khoan fun88
Pingback: p897#https://serwispodrozniczy.pl/forum/rozne-f6/organizacja-wesela-t165.html#p897
Pingback: Play baccarat online
Pingback: Samsara Market
Pingback: ebenin amini türkce dublaj izle
Pingback: pharma market research companies in mumbai
Pingback: pokermas99
Pingback: BQEssentials, LLC
Pingback: main qq
Pingback: warnetqq
Pingback: raja qq
Pingback: link dang nhap m88
Pingback: Top 10 Dentist in Columbia Maryland
Pingback: Replica Watch
Pingback: Cut food cravings. Killer Weight Loss
Pingback: car door decals graphics
Pingback: agen qiuqiu99
Pingback: rajawali qq
Pingback: klikdokter
Pingback: Homepage
Pingback: www.rajawaliqq1.site