Mysql - how to create an id column for a specific column
0
votes
1
answer
289
views
i want to create a table that have 3 column :
1. visit_times : have a unique id for every specific visitor
2. visitor_ID
3. Date
i tryed to create the table as showing this code
>CREATE TABLE
test
.table
( visit_times
INT NOT NULL AUTO_INCREMENT , visitor_ID
INT NOT NULL , Date
VARCHAR NOT NULL , UNIQUE Unique column
(visit_times
, visitor_ID
)) ENGINE = MyISAM;
but when i store this data into the table
INSERT INTO tab
(visitor_ID
, date
) VALUES ("1", "15/05/2021");
INSERT INTO tab
(visitor_ID
, date
) VALUES ("1", "20/07/2021");
INSERT INTO tab
(visitor_ID
, date
) VALUES ("2", "02/09/2021");
INSERT INTO tab
(visitor_ID
, date
) VALUES ("3", "24/08/2021");
the result it will be like this
| visit_times | visitor_ID | date |
|-------------|-------------|------------|
| 1 | 1 | 15/05/2021 |
| 2 | 1 | 20/07/2021 |
| 3 | 2 | 02/09/2021 |
| 4 | 3 | 24/08/2021 |
and what i actually want as result
| visit_times | visitor_ID | date |
|-------------|-------------|------------|
| 1 | 1 | 15/05/2021 |
| 2 | 1 | 20/07/2021 |
| 1 | 2 | 02/09/2021 |
| 1 | 3 | 24/08/2021 |
Server version: 8.0.21 - MySQL Community Server - GPL
I use Wampserver version 3.2.3 - 64bit
Apache Version : 2.4.46
Asked by OMAR TOUIL
(3 rep)
Sep 2, 2021, 11:56 AM
Last activity: Sep 2, 2021, 06:46 PM
Last activity: Sep 2, 2021, 06:46 PM