Answer the question
In order to leave comments, you need to log in
How to limit the selection on a certain field in sql query?
Whether a question on that perhaps in sql request to specify somehow a limit of selection on a certain field. Let me explain:
There is a table of books, there is a table of authors. There is a connection between them, i.e. traditional example.
Let's say I need to select from the table of books all the books of the authors Ivanov (id=1), Petrov (id=2) and Sidorov (id=3).
Those. the query would be:
SELECT * FROM books WHERE author_id=1 or author_id=2 or author_id=3;
But the thing is that I need to extract the books of these authors from the database, but in such a way that Petrov's books (that is, books with author_id = 2) fall into this selection, for example, no more than 2. Those. books by Ivanov and Sidorov should be all, but only two by Petrov.
Is it possible to do this in one request?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question