xstevex Posted February 1, 2008 Share Posted February 1, 2008 Hi, I just use phpmyadmin and I've been trying to write a query that selects all "userid" entries that are entered twice or more. The table has fields: userid (int) and listid (int). On a double entry the userid will be entered twice, once next to list 39 (for example) and a second time next to list 40. Like: userid | listid 1247 | 39 1247 | 40 I thought something like "(listid between 0 and 50 and listid between 0 and 50)" in the search conditions would work but it just selects everything. Is there an "andalso" function? Or something else that would work? Steve. Quote Link to comment https://forums.phpfreaks.com/topic/88893-query-for-finding-duplicate-entries/ Share on other sites More sharing options...
rhodesa Posted February 1, 2008 Share Posted February 1, 2008 This is one way to get a list of userids with duplicates: SELECT userid,count(*) as num FROM table WHERE num > 1 GROUP BY userid Quote Link to comment https://forums.phpfreaks.com/topic/88893-query-for-finding-duplicate-entries/#findComment-455324 Share on other sites More sharing options...
Illusion Posted February 1, 2008 Share Posted February 1, 2008 That should be SELECT userid,count(*) as num FROM table GROUP BY userid HAVING num >1; Quote Link to comment https://forums.phpfreaks.com/topic/88893-query-for-finding-duplicate-entries/#findComment-455500 Share on other sites More sharing options...
xstevex Posted February 2, 2008 Author Share Posted February 2, 2008 Thanks guys for the answers, I've tried many combinations of this in phpmyadmin but keep getting errors. Because I think the syntax must be different for there. What I do is I go into phpmyadmin through my website control panel and then click on the table in the database. There you can enter "where conditions" to search the table. I put them inside brackets like the instructions say: ( "where" ). Do you know how I would put this sort of search in the "conditions" in phpmyadmin? Steve. Quote Link to comment https://forums.phpfreaks.com/topic/88893-query-for-finding-duplicate-entries/#findComment-455854 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.