Home All Groups Group Topic Archive Search About
Author
26 Jan 2006 11:33 PM
Andrew Chalk
Can someone tell me where my syntax is wrong in the following SQL statement.
It's something to do with the use of the TOP keyword:

SELECT distinct top 1 * from calldetails order by calldate desc

I am trying to order the table by calldate and them select the most recent
record.

Many thanks.

Author
26 Jan 2006 11:39 PM
Patrik
What is the error message?
Author
27 Jan 2006 12:51 AM
Andrew J. Kelly
What good is a Distinct when you are already using TOP 1?  You will only get
one row.

--
Andrew J. Kelly  SQL MVP


Show quote
"Andrew Chalk" <ach***@magnacartasoftware.com> wrote in message
news:%23aSv7DtIGHA.1188@TK2MSFTNGP14.phx.gbl...
> Can someone tell me where my syntax is wrong in the following SQL
> statement. It's something to do with the use of the TOP keyword:
>
> SELECT distinct top 1 * from calldetails order by calldate desc
>
> I am trying to order the table by calldate and them select the most recent
> record.
>
> Many thanks.
>
Author
27 Jan 2006 2:05 AM
Chris Priede
Hi,

Andrew Chalk wrote:
> SELECT distinct top 1 * from calldetails order by calldate desc

There is no syntax error in the above.  If this is producing some sort of an
error, my best guess would be you don't have a table named "calldetails" or
a column named "calldate".  Also, if you are executing this query from
client-side code, perhaps there is some issue with that.

As another poster noted, DISTINCT is totally poinless here.  However, it
does not cause an error.

--
Chris Priede
Author
27 Jan 2006 8:02 AM
Andrew Chalk
My mistake. I was connected to mySQL at the time, which doesn't support (the
nonstandard) TOP.

- A

Show quote
"Andrew Chalk" <ach***@magnacartasoftware.com> wrote in message
news:%23aSv7DtIGHA.1188@TK2MSFTNGP14.phx.gbl...
> Can someone tell me where my syntax is wrong in the following SQL
> statement. It's something to do with the use of the TOP keyword:
>
> SELECT distinct top 1 * from calldetails order by calldate desc
>
> I am trying to order the table by calldate and them select the most recent
> record.
>
> Many thanks.
>

AddThis Social Bookmark Button