V
V
vetsmen2017-07-31 13:32:01
MySQL
vetsmen, 2017-07-31 13:32:01

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

3 answer(s)
A
Alexander Tikhomirov, 2017-07-31
@SysNord

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.

F
Fortop, 2017-07-31
@Fortop

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;

A
Alexander Sobolev, 2017-10-22
@san_jorich

brr .. and through the connecting table it will not be easier, comrade?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question