Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ga46's avatar
Level 1

without count how to query for understating is item duplicate?

how to i very fast way to query is item duplicate?

0 likes
6 replies
Tray2's avatar

You want to know if an item has more than one row in a table?

SELECT column1, COUNT(*) 
FROM table1
WHERE column1 = 'Something' 
AND HAVING COUNT(*) > 1
GROUP BY column1

These kinds of queries are always slowish, but with a index on column1 you should be able to speed it up.

lbecket's avatar

You might need to offer some additional context. What is an item in this situation, a database record? What's wrong with using a count?

lbecket's avatar

@ga46 then I would follow the advice offered by @tray2 and make appropriate use of an index. After all, what is a duplicate if not something with a count > 1. I don't know how you can count something without counting it.

1 like

Please or to participate in this conversation.