A
A
Andrey2016-01-21 15:00:31
MySQL
Andrey, 2016-01-21 15:00:31

How to specify the order in which records are stored in tables?

Is there a way to get a_id in the order they were inserted?

CREATE TABLE `m2m` (
  `a_id` INT(11) NOT NULL,
  `b_id` INT(11) NOT NULL,
  PRIMARY KEY (`a_id`, `b_id`),
  INDEX `FK_m2m_b` (`b_id`),
  CONSTRAINT `FK_m2m_a` FOREIGN KEY (`a_id`) REFERENCES `a` (`id`) ON DELETE CASCADE,
  CONSTRAINT `FK_m2m_b` FOREIGN KEY (`b_id`) REFERENCES `b` (`b`) ON DELETE CASCADE
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;

INSERT INTO `m2m` (a_id, b_id) VALUES ('1663', '4');
INSERT INTO `m2m` (a_id, b_id) VALUES ('1678', '4');
INSERT INTO `m2m` (a_id, b_id) VALUES ('1664', '4');
INSERT INTO `m2m` (a_id, b_id) VALUES ('1679', '4');
INSERT INTO `m2m` (a_id, b_id) VALUES ('1741', '4');
INSERT INTO `m2m` (a_id, b_id) VALUES ('1677', '4');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2016-01-21
@VladimirAndreev

Only by adding a field with type TIMESTAMP or DATETIME and an appropriate default value.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question