开发者

How do I get just one result when running a sql query?

开发者 https://www.devze.com 2023-03-18 08:24 出处:网络
SELECT user_ids FROM `items开发者_C百科` When I run that query, if a user has multiple items listed, I get the user_id listed that many times, but what I really want is just ONE user_id for each so
SELECT user_ids FROM `items开发者_C百科` 

When I run that query, if a user has multiple items listed, I get the user_id listed that many times, but what I really want is just ONE user_id for each so it basically represents all the user_ids who have >1 entry in the items table (and what I really want is the corresponding email)


If I understand correctly you want to use distinct

SELECT DISTINCT user_ids FROM items


Select Distinct user_ids FROM items 


From your context of > 1 entry (ie: more than 1 entry), you'll need a group by, not just distinct... distinct will include everyone, even if they ONLY have ONE entry

select User_IDs
   from items
   group by User_IDs
   having count(*) > 1
0

精彩评论

暂无评论...
验证码 换一张
取 消