0

This is the table containing hytags_hyobjects that are tagged with hytags_tags

                                                Table "public.hytags"
       Column        |            Type             | Collation | Nullable |                  Default                  
---------------------+-----------------------------+-----------+----------+-------------------------------------------
 hytags_id           | integer                     |           | not null | nextval('hytags_hytags_id_seq'::regclass)
 hytags_datecreated  | timestamp without time zone |           | not null | CURRENT_TIMESTAMP
 hytags_datemodified | timestamp without time zone |           |          | 
 hytags_usercreated  | text                        |           | not null | CURRENT_USER
 hytags_usermodified | text                        |           | not null | CURRENT_USER
 hytags_hyobjects    | integer                     |           | not null | 
 hytags_tags         | integer                     |           | not null | 
 hytags_description  | text                        |           |          | 

I would like to get hytags_hyobjects having all of the tag integers, such as 1, 2, 3 in hytags_tags where those values come from multiple rows. Selecting those that have either one of the tags is easy. I am looking to select those hytags_hyobjects which have all of the tags assigned.

3
  • Please provide your table structures and some sample data plus your desired output in a fiddle (dbfiddle.uk) - post the same data here. Also, always include your version of PostgreSQL in your questions. A+! Jun 11, 2021 at 7:47
  • Possible duplicate of Make IN clause behave like AND clause
    – Andriy M
    Jun 11, 2021 at 10:43
  • By following the example in the duplicate I have solved it with: SELECT DISTINCT hytags_hyobjects FROM hytags WHERE hytags_hyobjects IN (SELECT hytags_hyobjects FROM hytags WHERE hytags_tags = 191) AND hytags_hyobjects IN (SELECT hytags_hyobjects FROM hytags WHERE hytags_tags = 867) where by without DISTINCT I would get duplicates.
    – Jean Louis
    Jun 12, 2021 at 9:41

0

Browse other questions tagged or ask your own question.