Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Subquery

Author  Topic 

mary H
Starting Member

32 Posts

Posted - 2008-10-10 : 01:45:29
I need to list a dog_id and name for each dog that has been placed one or more times.

I have two tables dog and place.

Dog table looks like this:

Name /dog_id
Rocky/1021
Bee/2012
Rose/3014
Lilly/401
etc...

Place table looks like this:

dog_id/place
1021/1
2012/2
3014/3
1021/1
2012/3


I need a subquery to check which dog has been placed one or more times.


Any ideas

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-10 : 01:59:39
[code]SELECT d.*
FROM Dog d
JOIN (SELECT dog_id
FROM Place
GROUP BY dog_id
HAVING COUNT(place)>=2)t
On t.dog_id=d.dog_id[/code]
Go to Top of Page

mary H
Starting Member

32 Posts

Posted - 2008-10-10 : 04:44:42
Thank you visakh16! I appreciate your help
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-10 : 04:51:27
quote:
Originally posted by mary H

Thank you visakh16! I appreciate your help


welcome
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-10-10 : 05:40:25
why would you want to delete it?

Em
Go to Top of Page

mary H
Starting Member

32 Posts

Posted - 2008-10-10 : 05:42:36
quote:
Originally posted by elancaster

why would you want to delete it?

Em



No this thread...

Ive made other threads and got clues...
Go to Top of Page
   

- Advertisement -