Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Row filtering 1

Status
Not open for further replies.

samcam

Programmer
Feb 18, 2003
18
US
Hi Experts...

I have a table with the following structure

OfficeName Address
x1 x1a1
x1 x1a2
x2 x2a1
x3 x3a1
x4 x4a1
x5 x5a1
x5 x5a2
x6 x6a1

Now you can see that some offices have more than on address. I want to extract only the a1 addresses for all the offices. How do I filter those.

Would really appreciate your input and help.
 
Try
[blue][tt]
Select OfficeName, Address
From tbl
Where Address LIKE %a1%
[/tt][/blue]
 
Ok...may by I didn't publish my question right.

Here is how the table is

OfficeName address
x1 abcd
x2 efgh
x3 1234
x4 5678
x5 ijkl
x5 mnop

now how do I get only one address for all rows. Some offices have more than one address but all offices have atleast one address. So I want to get only one address for each office. If they have more than one address I only want the first one.
Really appreciate your input.
 
do you have an identity column?


"Shoot Me! Shoot Me NOW!!!"
- Daffy Duck
 
Yes there is an identity column which we call objid and this is unique for every row.
 
You want at least one address but you don't care which one?
[blue][tt]
Select OfficeName, FIRST(Address)
From tbl
GROUP BY OfficeName
ORDER BY OfficeName, Address
[/tt][/blue]
 
Yes I do care which row. The identity should be greater. Is there a function called "First
 
If you want the first address for a given office you might try
Code:
Select 
OfficeName,
Address
From tbl t1
Where objid = (select Min(objid) 
               from tbl where OfficeName = ti.OfficeName)

"Shoot Me! Shoot Me NOW!!!"
- Daffy Duck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top