S
S
Sergey Romanov2015-10-15 20:02:18
MySQL
Sergey Romanov, 2015-10-15 20:02:18

How to get data from 2 rows selectively with one request?

Suppose there is a Rules table

ID | Rule    | ItemID | Access
1  | books   | 0      | 1
2  | books   | 1      | 0
3  | shelves | 0      | 1

For example, this section of books access is open 1, but book 1 is closed. This is a type of rule. There, of course, everything is more complicated, there is a lot of data, but this is what I need to solve the problem.
The task means such, to create request so to check up there is an access to the book. But the query should return not 1 or 0, but a record or no records for exists.
Well, we choose.
SELECT * FROM books WHERE exists(
    SELECT 1 FROM rules WHERE rule = 'books' AND itemid = books.id AND access = 1
)

That's how it works. I can display only those books to which I have access.
But what if for example I choose shelves?
The shelf does not have a record for a specific shelf, so naturally we will not see the shelves.
And how can I do that if there is no link to a specific entry, use the general entry 3 | shelves | 0 | one ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2015-10-23
@Oraclist

Sergey, the statement of the problem is not clear.
Please, the same, only in other words.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question