Jump to content

Only select if column value is unique?


pmiller624

Recommended Posts

I have three tables that when simplified are set up like below.

 

      tag_map

+--------+--------+

| user_id | tag_id |

+--------+--------+

|    1    |    1    |

|    2    |    1    |

|    2    |    2    |

/*etc*/

 

    tags

+--+---------+

| id |  name  |

+--+---------+

| 1 |    PHP  |

| 2 |  mySQL |

/*etc*/

 

user

+--+

| id |

+--+

| 1 |

| 2 |

 

I have an sql query that looks like:

 

SELECT *

FROM tag_map

JOIN `users`

ON tag_map.user_id = users.id

WHERE tag_id = 1 OR tag_id = 2

 

If you were to run this query on the data above user 2 would come up twice because he has the tags of 1 and 2. So my question is how can I make it so the query only selects a users id number once, no matter how many times his tag pops up?

Link to comment
https://forums.phpfreaks.com/topic/209930-only-select-if-column-value-is-unique/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.