S
S
Sergey Mamenko2018-07-14 22:32:41
SQL
Sergey Mamenko, 2018-07-14 22:32:41

How to exclude duplicate lines from $wpdb->prepare?

There is a bookmark plugin with categories and its table.
From there you need to take the number of posts that the user has bookmarked.
For this I use the following query:

SELECT count(*) as totalobject FROM $cbxwpbookmrak_table WHERE user_id = %d

But if you add one post to 3 different categories, then instead of the number 1, 3 will be displayed, because. in the table, the row is essentially duplicated, only the category id differs
dJimqlZ.png
Is it possible to refine the query so that a post that was added to several categories is counted as 1, and not a number equal to the number of categories to which it is added?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nozzy, 2018-07-14
@bobongida97

SELECT COUNT(DISTINCT( object_id)) as totalobject FROM $cbxwpbookmrak_table WHERE user_id = %d

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question