Web Analytics Made Easy -
StatCounter Dinstinct - CodingForum

Announcement

Collapse
No announcement yet.

Dinstinct

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dinstinct

    I wish to get all records from a database - including all fields, but I don't want any which has the same 'simile_url' as any other record.

    For example:
    ID Title URL
    1 Happy happy.gif
    2 Smile happy.gif
    3 Laughing laughing.gif
    4 Crying crying.gif
    5 Upset crying.gif

    Records 1, 3 and 4 would only be returned because the others have 'double' urls.

    Any ideas Please?

  • #2
    since record 1 and 2 have the same URL and you only want to return the one of them which one do you choose? smallest id where there is a case of duplicate URL?

    you also say you want all records but that will not be possible since you then say you want to discard some of the rows.
    Last edited by guelphdad; Sep 28, 2006, 12:22 PM.

    Comment


    • #3
      check out the SELECT syntax documentation at mysql.org and checkout the DISTINCT keyword

      Comment


      • #4
        Beagle, distinct won't help in this case. It would return all rows since they are all distinct from one another. the problem is in deciding which of the duplicate URL rows the user wants returned. if it is as simple as the lowest id in the case of duplicate URLs then that is the query I will show.

        Comment


        • #5
          I want all rows UNLESS they have a url the same as another record. In this case, the first one returned with that url is the one that is chosen.

          That a bit better?

          Comment


          • #6
            If you only want to retrieve that one field (URL), then you can use distinct.
            Code:
            SELECT DISTINCT(field) FROM table;
            If you need to retrieve the entire row, use GROUP BY.
            Code:
            SELECT DISTINCT * FROM table GROUP BY field;

            Comment


            • #7
              don't use DISTINCT and GROUP BY they are mutually exclusive.

              use something like this:
              Code:
              select
              min(id),
              min(title),
              url
              from yourtable
              group by url
              Last edited by guelphdad; Sep 28, 2006, 07:15 PM.

              Comment

              Working...
              X