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

Answer Posted / krishna prasad a

For this Answer 1 is incorrect.

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.candytest from
candytest c1,candytest c2
where c1.candycolor=c2.candycolor
and c1.kidid=c2.kidid

Is This Answer Correct ?    20 Yes 13 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the maximum length of an extended property?

544


How can I detect whether a given connection is blocked?

571


What are the constraints on severity level in raiseerror?

572


Explain about post-relational databases?

570


What you can do to remove data from the cache and query plans from memory for testing the performance of a query repeatedly?

579






Can an extended stored procedure be called from inside a user-defined function?

598


On friday, you issued several insert statements using query analyzer. You then verified the data had been correctly entered with a select statement on monday, your users report that the data is not there what happened?

548


How to read and create .LDC data files which are used by linguatic dictionary.

2045


Write the fastest query to find out how many rows exist in a table?

654


How to use timestamp datatypes

1566


Does QTP Support the Propjects which are running in Dot Net? As we are starting with new project in Dot net need to use automation tool?Please advice & let me know what would be the best.

1591


Explain about query and reporting.

1678


Explain about the database management systems.

557


What is data modeling with example?

522


Explain about a primary key?

561