C
C
coden552016-07-06 20:05:33
PostgreSQL
coden55, 2016-07-06 20:05:33

Form a query to the database?

Conditionally in the table there are 2 columns (owner_id, object_id)
I have to pass a specific owner_id and a list (array) of object_id's to the request and get a check whether all object_ids belong to the owner_id.
If some owner_id - object_id pair is missing - then false

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
evnuh, 2016-07-06
@coden55

SELECT COUNT(DISTINCT object_id) FROM table WHERE owner_id=$owner_id AND object_id IN($object_ids)

and compare the answer with count($object_ids)
To solve a specific problem with returning true and false from the base, wrap this request in another select, in which you compare the result of the subquery with the account passed to the request and return true or false using IF()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question