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
 Display all the fields in Sql server 2005

Author  Topic 

Maachie
Yak Posting Veteran

69 Posts

Posted - 2007-11-15 : 11:29:57
I want to select all the fields from just one table
This is what i have and i am having trouble selecting all the fields
select * from ace_users
where chdata EXISTS
(select chdata, count(chserialnum)
from ace_users
group by chdata
having count(chserialnum)> 1)

Exists and IN does not work.

nr
SQLTeam MVY

12543 Posts

Posted - 2007-11-15 : 11:39:43
Not really sure what you want - maybe

select * from ace_users
where chdata in
(select chdata
from ace_users
group by chdata
having count(*)> 1)

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Maachie
Yak Posting Veteran

69 Posts

Posted - 2007-11-15 : 13:22:24
I want one user having multiple accounts and it is from one table

Ex: empid1 has fob1, fob2 fob3
Ex: empid2 has fob1 fob2
Ex: Empid3 has fob1 fob2,fob3,fob4

I get this from

(select chdata, count(chserialnum)
from ace_users
group by chdata
having count(chserialnum)> 1)

But I want to display all the other columns as well from the table?

I tried
select * from ace_users
where chdata IN
(select chdata, count(chserialnum)
from ace_users
group by chdata
having count(chserialnum)> 1)

When I tried IN it threw me an error, I also tried Exists. It did not work.

Hope it is clear now.

Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-11-15 : 15:20:12
'coz when you do IN the SELECT statement returning the result should match what you are IN'ing on. So you are saying chdata IN (...) Your inner SELECT should ONLY return data of type chdata.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page
   

- Advertisement -