开发者

Can I get mysql to search for an identical match on any rows in one column?

I am not sure how to do ask this...

Is it possible to have mysql scan a whole column in a whole table and finds an identical match or 开发者_如何学编程matches.

So it would be something like...

$q = $pdo("SELECT ip FROM accounts");
$q -> execute();
$results = $q -> fetch(PDO::FETCH_ASSOC);

if (there is 2 of same ip) {

}

Thanks


If you're looking for duplicates, the following SQL should give you any IPs listed two or more times in your accounts table.

$q= $pdo("SELECT ip FROM accounts GROUP BY ip HAVING COUNT(ip) > 1");
$q->execute();
$duplicateIPs = $q->fetch(PDO::FETCH_ASSOC);


SELECT column,column2 FROM table WHERE last_login_ip = 'IPHERE';


You should try something along the lines of

SELECT `a`, `b`, COUNT(`a`) AS cnt FROM `table` AS t GROUP BY t.`a` ORDER BY cnt DESC;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜