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
 Equality of Fields within a table

Author  Topic 

pupli
Starting Member

8 Posts

Posted - 2008-08-06 : 11:19:19

hello everybody,

I have a table (only one table) with several records in it.

Now, I want to build a query which will return all the records whose
field's value is equal (we assume that we pre-chose a column)

for example

Table1
==============================================================
|CustID | Name | SName | NrTEL | E-Mail | Profession |
==============================================================

Table1
==============================================================
|CustID | Name | SName | NrTEL | E-Mail | Profession |
--------------------------------------------------------------
| 102 | abcde | asdf | 12345 | aa@s.com | Director |
| 105 | aderw | wert | 12233 | aw@s.com | Manager |
| 123 | ertyu | oiui | 15456 | eo@s.com | Specialist |
| 245 | abcde | iuyt | 14254 | ai@s.com | Specialist |
| 256 | kjfur | asdf | 12589 | ka@s.com | Manager |
==============================================================


************
Our query would have been like this:
*********************************************
Display all the people with the same profession


and the result should be like this:
************
*Result SET*
************
==============================================================
|CustID | Name | SName | NrTEL | E-Mail | Profession |
--------------------------------------------------------------
| 105 | aderw | wert | 12233 | aw@s.com | Manager |
| 123 | ertyu | oiui | 15456 | eo@s.com | Specialist |
| 245 | abcde | iuyt | 14254 | ai@s.com | Specialist |
| 256 | kjfur | asdf | 12589 | ka@s.com | Manager |
==============================================================


thank you to everybody



If I only could.....

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2008-08-06 : 11:29:40
select * from Table1
where Profession in (
select Profession
from Table1
group by Profession
having count(*) > 1)
-- maybe: order by Profession

Webfred
Go to Top of Page

pupli
Starting Member

8 Posts

Posted - 2008-08-07 : 10:33:59
thank you webfred

thank you

If I only could.....
Go to Top of Page
   

- Advertisement -