Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Limit SQL Query results

Posted on 2010-11-09
2
Medium Priority
?
362 Views
Last Modified: 2012-08-13
This SQL query returns 5 records:

select FULLNAME,L_LAXON
from sde.HILLSBOROUGH_POLYLINE
where fullname like '% VARN%' or FULLNAME like 'VARN%'
GROUP BY FULLNAME,L_LAXON

I also want the ObjectID field returned but when I include it in the Select and Group By it increases the number of records returned to 22 and now I have duplicates of the FULLNAME and L_LAXON data.
How can I query for this information and get want I want, which is the 5 records including the OjbectID field.  Thanks!
0
Comment
Question by:MEINMEL
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 41

Accepted Solution

by:
ralmada earned 2000 total points
ID: 34096858
two options

select FULLNAME,L_LAXON, max(ObjectID)
from sde.HILLSBOROUGH_POLYLINE
where fullname like '% VARN%' or FULLNAME like 'VARN%'
GROUP BY FULLNAME,L_LAXON

or this other one

select FULLNAME,L_LAXON, ObjectID
from (
 select FULLNAME,L_LAXON, ObjectID, row_number() over (partition by FullName, L_LAXON order by FULLNAME, L_LAXON) rn
 from sde.HILLSBOROUGH_POLYLINE
 where fullname like '% VARN%' or FULLNAME like 'VARN%'
) a
where rn = 1
 
0
 

Author Closing Comment

by:MEINMEL
ID: 34096902
Thank you so much, especially for the fast and accurate response!
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question