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
Explain about relational database management systems?
Explain what a database is?
What are the three basic rules which are to be followed for the relational model of the database?
Explain about normal forms?
Explain about xml databases?
Which four data types cannot be used as a return type from a user-defined function?
explain detail about ftp in datastage?
Explain about the database management systems.
State the acid rules?
Hi , any one can help me on the same,this is regarding the Informatica Function doc,i want to know how developer is will develop the mapping. pl forwar the any function doc .just for my references. svlc75@yahoo.co.in
How to generate OIDS
What is database design and development?
Hi my program is accesing data from two db2 databases.what is the bind card for this program to genarate plan? how to specify the two owners and two qualifiers in bind card
How to replace not in with not exist?
Can an extended stored procedure be called from inside a user-defined function?