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
What are the types of database model?
In which table collections errors are stored.
Explain about network model?
Explain the process of the user request and data generating?
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.
State the acid rules?
You have two tables with a one to many join based on a field named id. You need to find records in the parent table that are not represented in the child table. how would you accomplish this?
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?
What are the 18 schemas?
How to generate OIDS
Explain about the storage and physical database design?
Explain the role of indexing in databases?
How long can an error message be in raiseerror function?
Explain about relational database management systems?
What are the main phases of database development?