Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What is a self join? Explain it with an example?

Answer Posted / lalithg

CREATE TABLE candytest
(kidId char(2),
candycolor varchar(10)
)
GO

INSERT INTO candytest SELECT 'K1', 'Yellow'
INSERT INTO candytest SELECT 'K1', 'Red'
INSERT INTO candytest SELECT 'K2', 'Red'
INSERT INTO candytest SELECT 'K2', 'Blue'
INSERT INTO candytest SELECT 'K3', 'White'
INSERT INTO candytest SELECT 'K3', 'Red'
INSERT INTO candytest SELECT 'K3', 'Yellow'
Go
--Now to find those kidid's which has both yellow and red
colored candies, we can write query as:

SELECT c1.kidid
FROM candytest AS c1 JOIN candytest AS c2
ON c1.candycolor = 'Red' AND c2.candycolor = 'Yellow'
AND c1.kidid = c2.kidid

Is This Answer Correct ?    85 Yes 69 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How long can an error message be in raiseerror function?

934


What are the constraints on severity level in raiseerror?

929


What is an application role and explain a scenario when you would use one?

946


Who are naive users?

947


What is data modeling with example?

895


What are the three basic rules which are to be followed for the relational model of the database?

925


Explain what a database is?

974


You are testing the performance of a query the first time you run the query, the performance is slow. the second time you run the query, the performance is fast. why is this?

883


What is DB Development software?

1996


What are data modelling techniques?

895


Explain about relational operator join?

973


Explain about the hierarchical model of the database?

1052


Where is dbms used?

1007


How can you log an error to the server event log from a stored procedure?

1027


Explain the rollup operator?

988