Tuesday, 27 August 2013

Distinct Clause in an SQL Query

Distinct Clause in an SQL Query

I have a table named MediaGenT in my SQL Database that has 425000 records.
However the column name mg_medianum has duplicate entries. For example
mg_medianum = '858' has 10 different records but I am only interested in
the most recent record which can be ordered by mg_createdate.
When I do this I get 425000 records:
Select * from MediaGenT
Order By mg_createdate;
When I do this I get 89000 records (correct but only shows one column):
Select distinct mg_medianum from MediaGenT
Order by mg_createdate;
To sum up what I need is one query that shows every column of the 89000
records only displaying the most recent distinct mg_medianum based ordered
by mg_createdate. I'm having trouble coming up with the syntax for that
kind of query.

No comments:

Post a Comment