C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » .NET »

sql querry interview question


Posted Date: 10 Jul 2006      Posted By: damodar      Member Level: Bronze     Points: 2   Responses: 6



I have two tables one is emp table having columns
eid
ename
esal
another table named phone having columns
eid
phonenumber
Now i want to get the details of the employee who have two or more than two phone numbers
write the querry?





Responses

Author: chenna    10 Jul 2006Member Level: SilverRating: 2 out of 52 out of 5     Points: 2

Hi,

SELECT * FROM EMP
WHERE EID IN(SELECT DISTINCT EID FROM PHONE
GROUP BY EID
HAVING COUNT(*) >= 2)


OR

SELECT EMP.* FROM EMP E, PHONE P
WHRE E.EID = P.EID
GROUP BY E.EID, E.ENAME, E.ESAL
HAVING COUNT(*) >= 2

Thanks and Regards
-Kesav



Author: divya    13 Oct 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 1

select a.id from test a where a.id in(select b.id from test1 b group by b.id having count(*)>=1)


Author: Mahima Nayak    28 Oct 2008Member Level: BronzeRating: 2 out of 52 out of 5     Points: 4

SELECT eid, ename
FROM emp
WHERE (eid IN
(SELECT eid
FROM phonenumber
GROUP BY eid
HAVING (COUNT(*) >= 2)))



Author: T.Thirumala Reddy    07 Nov 2008Member Level: BronzeRating: 2 out of 52 out of 5     Points: 1

select * from emp
where eid=(select distinct eid from phone group by eid having(count(*)>1))



Author: Deepika Haridas    22 Nov 2008Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

SELECT EMP.* FROM EMP E, PHONE P WHRE E.EID = P.EID GROUP BY E.EID, E.ENAME, E.ESAL HAVING COUNT(*) >= 2



Thanks & Regards,
Deepika
Editor

If U want to shine like a SUN..First U have to burn like the SUN!!
Need a Guide? Join my mentor program..



Author: Deepika Haridas    26 Nov 2008Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

SELECT eid, ename
FROM emp
WHERE (eid IN
(SELECT eid
FROM phonenumber
GROUP BY eid
HAVING (COUNT(*) >= 2)))



Thanks & Regards,
Deepika
Editor

If U want to shine like a SUN..First U have to burn like the SUN!!
Need a Guide? Join my mentor program..



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : sql querry
Previous : connection string for sql , pls help
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use