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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Help: How to select distinct rows using the WHERE clause

Status
Not open for further replies.

Sethington

Technical User
May 16, 2006
34
US
I have an app at work that will only allow me to customize the WHERE clause on a SQL statement.

Currently the SQL Statement is hard coded something like this:

SELECT * FROM ERRORS

Is there a way to do a DISTINCT in the WHERE clause that would return the same results as:

SELECT DISTINCT MEMBER_NUMBER FROM ERRORS
 
Are you only able to change the WHERE clause or will it accept your WHERE clause if you put a GROUP BY on the end of it?

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
I can do anything that can follow after the FROM Clause. So Group BY works too but as far as I know this only groups the duplicate member numbers and not returns the unique/distinct numbers.
 
Distinct will do distinct rows, group by will work in exactly the same way (in terms of output) if you group by all fields.

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Sethington,

I'm glad that HarleyQuinn's suggestion works perfectly for you.

When a solution provides such results, we Tek-Tipsters click the [Thank <helpful poster> for this valuable post] link to award them a
star.gif
.

That would be a great thing for you to do now if you want HarleyQuinn and others to just as eager next time to provide you help when you need it.

Holiday Cheer,

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
 
Cheers Dave [smile]

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Just out of interest, are you also able to semi-colon outout the query and run (at the very least) a DROP TABLE statement (as I'm sure someone will mention it eventually, SQL Injection anyone)?

Please note, I'm NOT advising you to try this, but to ask your admin's.

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top