Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Problem with ORDER BY

Author  Topic 

mstembri
Starting Member

1 Post

Posted - 2002-03-25 : 18:25:51
For reference, here's the query statement.


SELECT
DISTINCT call_ticket.ticketid,
queue.to_userid,
queue.from_userid,
queue.deptid,
call_ticket.fnum,
call_ticket.categoryid,
call_ticket.statusid,
call_category.call_categorydesc,
call_status.statusdesc,
DATE_FORMAT(call_notes.call_end,'%m.%d.%y') as fcall_end,
queue_importance.queue_imp_desc,
queue_importance.queue_imp_id

FROM
call_ticket,
call_notes,
queue,
queue_importance,
call_category,
call_status

WHERE
queue.to_userid = '1' &&
queue.queue_imp_id = queue_importance.queue_imp_id &&
call_ticket.ticketid = queue.ticketid &&
call_notes.ticketid = queue.ticketid &&
call_ticket.categoryid = call_category.call_categoryid &&
call_ticket.statusid = call_status.statusid

OR
queue.from_userid = '1' &&
queue.queue_imp_id = queue_importance.queue_imp_id &&
call_ticket.ticketid = queue.ticketid &&
call_notes.ticketid = queue.ticketid &&
call_ticket.categoryid = call_category.call_categoryid &&
call_ticket.statusid = call_status.statusid

ORDER BY
call_notes.call_end DESC



I'm a little new to SQL and have a problem with an ORDER BY clause in the above query.

The query is used to populate a html table wiht information about support calls. The user has an option to sort the columns with header links (ie, by ticket#, date, status, ect). All sort colums rely on the ORDER BY clause.

Every sort option works great except for the one listed above.

We should only show one ticket for each ticket# listed. What happens here is when I sort by call_notes.call_end there are duplicate ticket numbers in the html table. I checked and found that if there were 14 seperate notes taken for the particular ticket, the ticket would be listed 14 times in my html table. All other ORDER BY options do not have this quirk.

As I mentioned I'm new to SQL and am open for suggestions on how to go about correcting this problem, if it can be done at all. I realize I may be leaving out something important, so please ask if you need clarification.

nr
SQLTeam MVY

12543 Posts

Posted - 2002-03-25 : 19:23:53
The order by clause shouldn't affect the rows returned just the order - so the order by clause is irrelevant here. It should just depend on the distinct rows

You have multiple call notes - do they have different call_end values? In which case the rows will be distinct and you will have to decide which one you want - maybe a max and group the other fields instead of a distinct.

==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -