order by two fields

# Thread: order by two fields

1. Junior Member
Join Date
Dec 1969
Posts
10

## order by two fields

Well here i am again with another question (stupid maybee :( )<BR><BR>I can&#039;t order a table by two fields <BR><BR>I need to list a table, ordered by date ascending (or descending) and for each day records, this records should be ordered by points descending.<BR><BR><BR>Here is my query<BR><BR>SELECT *<BR>FROM (MCMENSAGEMWEB_ENTRADA INNER JOIN MCMENSAGEMWEB ON MCMENSAGEMWEB_ENTRADA.MCMENSAGEMWEB_ENTRADA_MCMENS AGEMWEB_ID = MCMENSAGEMWEB.MCMENSAGEMWEB_ID)<BR>WHERE MCMENSAGEMWEB_ENTRADA_VENCEDOR = 1<BR>ORDER BY MCMENSAGEMWEB_ENTRADA_DATA, MCMENSAGEMWEB_ENTRADA_PONTOS DESC<BR><BR><BR>this gives me a result ordered by date ascending, and it doesn&#039;t order by points (MCMENSAGEMWEB_ENTRADA_PONTOS DESC)<BR>

2. Junior Member
Join Date
Dec 1969
Posts
10

## RE: order by two fields

i found why this isn&#039;t working<BR><BR>it&#039;s because the first field i&#039;m ordering is a date, with date and time.<BR><BR>so there isn&#039;t two dates that are equal. (the time is always diferent) and because of this, the result isn&#039;t ordered by points<BR><BR>is there any way to solve this?<BR><BR>or do i have to make a query for each day, ordered by points?<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
134

## RE: order by two fields

Is the date stored as date/time? If so, is it possible that the field is also storing the time (eg. 12 Jan 2002 12:10:10, 12 Jan 2002 12:12:00) and sorting by this? One way to get around this would be to create a calculated field based on the date eg<BR><BR>ORDER BY CONVERT(varchar(10),MyDate,102) ASC, POINTS DESC

4. Junior Member
Join Date
Dec 1969
Posts
10

## RE: order by two fields

Yes the dates are stored in date/time format!<BR><BR>I have just made a query with your tip and it&#039;s working fine!<BR><BR>you can see the result here:<BR>http://www.mcdonalds.pt/mcmensagem_list_mctoques_venc.asp<BR><BR>Thanks Holycow<BR><BR><BR>I love this board<BR>Maybee one of the best places to get help on ASP, SQL, ...

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•