Answer the question
In order to leave comments, you need to log in
How to set multiple values for a database field?
Good day.
I have a row in the database:
Book No. 1 - 5 pieces - 1 id, 3 id
Book No. 2 - 2 pieces - 3 id
like:
SELECT * FROM Books WHERE id = 1: get Book #1
SELECT * FROM Books WHERE id = 3: get Book #1, Book #2
How do I do this?
Answer the question
In order to leave comments, you need to log in
ID - identifier. An identifier is used to uniquely identify a record in a table. Question: Why does one record have multiple IDs? Answer: in order to have difficulties with the selection later.
And what exactly is the problem?
Is it a problem to add this very field on which you will make selections?
CREATE TABLE `Books` (
`id` INT NOT NULL,
`name` CHAR(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
INSERT INTO Books (`id`, `name`) VALUES
(1, 'one'),
(2, 'one'),
(2, 'two'),
(3, 'one'),
(3, 'two')
(3, 'three')
;
SELECT * FROM Books WHERE id = 3;
SELECT * FROM Books WHERE id = 2;
SELECT * FROM Books WHERE id = 1;
brr .. and through the connecting table it will not be easier, comrade?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question