azio
azio

Reputation: 585

Counting from many-to-many

How can I check if a tag is at least used once based on the structure below.

Table structure

Upvotes: 0

Views: 50

Answers (1)

Erwin Brandstetter
Erwin Brandstetter

Reputation: 657397

An EXISTS semi-join is most probably the fastest of several possible query styles for this task:

SELECT t.*
FROM   taggit_tag t
WHERE EXISTS (
   SELECT 1
   FROM   taggit_taggeditem ti
   WHERE  ti.tag_id = t.tag_id
   );

Upvotes: 3

Related Questions