Forum Moderators: coopster

Message Too Old, No Replies

MySql select unique rows?

         

erikcw

10:19 pm on Apr 25, 2005 (gmt 0)

10+ Year Member



Hi all,

I am have a table which contains recent search querys of another table.

I am tryng to output this data into a list so the user can click, and re-run a recent search...

The problem is that the table is full of duplicate searches from the same user.

How do I select the searches without retrieving duplicates?


SELECT id, term FROM project_term WHERE pid='$_SESSION[project_id]'

Also, would it make more sense to store all serches of a paricular user, or stop the insert if the record exists? Is there a way I can do this without performing 2 queries (ie adding some sort of LIMIT or other xeyword to the INSERT query?) I can't make the column unique because two users could perform the same search...)

Thanks!
Erik

jusdrum

10:21 pm on Apr 25, 2005 (gmt 0)

10+ Year Member



Try using a GROUP BY clause.

SELECT id, term FROM project_term WHERE pid='$_SESSION[project_id]' GROUP BY term

This should group all terms that are the same.

erikcw

11:43 pm on Apr 25, 2005 (gmt 0)

10+ Year Member



worked like a charm! thanks!