Answer the question
In order to leave comments, you need to log in
How to add multiple id's to a user from another table?
Suppose there is a user table, the main table where all information about the user is stored
[
name varchar
surname varchar
balance integer
created_at and by the way, which type is better to choose for storing time if the time is stored in the style 1606208106781
books and here there should be a list of user books, their number can be from 0 up to 100
]
and how to make it so that when making a request to get information about the user, I also received information about books (which is stored in another table)
I hope I explained it clearly
Answer the question
In order to leave comments, you need to log in
created_at and by the way, which type is better to choose for storing time if the time is stored in the style 1606208106781
books and here should be a list of the user's books, their number can be from 0 to 100
how to make it so that when making a request to get information about the user, I also received information about more books
SELECT u.*, b.*
FROM users u
LEFT JOIN books b ON (b.id = ANY(u.books))
WHERE ...
name | surname | balance | created_at | books | id | title | author
______________________________________________________________________________________________________________
Alex | Smith | 22.10 | 1606349583252 | {2,10,88} | 2 | A Game of Thrones | George R. R. Martin
Alex | Smith | 22.10 | 1606349583252 | {2,10,88} | 10 | A Clash of Kings | George R. R. Martin
Alex | Smith | 22.10 | 1606349583252 | {2,10,88} | 88 | A Storm of Swords | George R. R. Martin
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question