One result

Results 1 to 3 of 3

Thread: One result

  1. #1
    Join Date
    Dec 1969

    Default One result

    In a site I have a section where the users can register for many categories.<BR>In the search section I have to show results based on Categories and age.<BR>Lets say a user is registered in 3 categories. When I do a search with the<BR>option "All Categories" the result page is showing that user for 3 times.<BR>What should I do to show it just once?<BR><BR>Dragos

  2. #2
    Join Date
    Dec 1969

    Default How about DISTINCT or Group By<eop>


  3. #3
    Join Date
    Dec 1969

    Default Vineet correct, but watch out!

    If you do something like<BR>*&nbsp; &nbsp; SELECT DISTINCT UserName, Category <BR> &nbsp; &nbsp; FROM table <BR> &nbsp; &nbsp; WHERE Category IN (&#039;eat&#039;,&#039;drink&#039;,&#039;be merry&#039;)<BR>then you will *still get 3 records if the user is found in all 3 categories.<BR><BR>Reason: DISTINCT will only eliminate duplicates if *ALL FIELDS* in the duplicated records are identical! Since, obviously, the Category field in each of those 3 records will be different, in this case DISTINCT will do nothing.<BR><BR>Since you *probably* want to still see *which* categories the user is listed in, it&#039;s quite possible that you don&#039;t *really* want to eliminate duplicates. Instead, what you might want is to be able to display the user name and a *list* of chosen categories, possibly for several user names?<BR><BR>If so, then look at<BR><BR>Incidentally, GROUP BY won&#039;t help in eliminating duplicates. It can, however, help if you go the route suggested in that FAQ.<BR><BR>

Posting Permissions

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