Using DISTINCT wirh ORDER BY

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Using DISTINCT wirh ORDER BY

    Hi All,

    This query results in a conflict.

    <cfquery name="sellers" Datasource="#Application.datasource#">
    select DISTINCT users.uid_user, full_name from users, member_types, user_roles
    where users.uid_user=user_roles.uid_user and
    user_roles.uid_role=member_types.uid_member_type and
    member_types.is_committee=true
    <cfif #session.sequence# is True>
    order by first_name, last_name
    <cfelse>
    order by last_name, first_name
    </cfif>
    </cfquery>

    The user_roles table can have multiple entries for a single user, hence the
    use of distinct, but I still want to order the query results. The full_name,
    last_name and first_name columns are all from the users table.

    How can I do this given DISTINCT and ORDER BY conflict?

    Rustywater Guest

  2. Similar Questions and Discussions

    1. SQL Distinct
      I want to select distinct value from one field of the table and select rest of the corresponding fields accordingly. I have a table that has fields:...
    2. 'distinct on' and 'order by' conflicts of interest
      It has come up several times on the various postgresql lists that in order to get around the requirement of DISTINCT ON parameters matching the...
    3. need help on DISTINCT
      Hi ALl, I need some help on DISTINCT in a query I'm trying to run. I have two tables which are linked. This is the query I use: SQL = "SELECT...
    4. SELECT DISTINCT + ORDER BY gives ERROR 145: ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
      Following is my stored procedure. If I take the DISTINCT out then everything works fine. BUT I need the distinct because it returns duplicate...
    5. SELECT DISTINCT + ORDER BY gives ERROR 145: ORDER BY items mustappear in the select list if SELECT DISTINCT is specified.
      Dan, You should be able to do this: SELECT Id, FaxID, ReceivedTime, Pages FROM ( SELECT DISTINCT .Id AS Id,
  3. #2

    Default re: Using DISTINCT wirh ORDER BY

    Try adding last_name and first_name to the select clause of the query.
    MikerRoo Guest

  4. #3

    Default Re: Using DISTINCT wirh ORDER BY

    Thank you. That works.
    Tanya
    Rustywater Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139