I have a table with 2 fields, val1and val2that contain the same type. val1is mandatory, but val2optional, but if present, must be relevant val1.
CREATE TABLE VALS (
id INT NOT NULL AUTO_INCREMENT,
val1 INT NOT NULL,
val2 INT DEFAULT NULL,
timesign TIMESTAMP);
For this, I want to get all the values coming from a field val1or val2, in one field res, so this
INSERT INTO VALS (val1, val2) VALUES
(1, null),
(2, null),
(3, 4),
(5, null),
(6, 7),
(8, null);
can be obtained in only one field:
+------+
| res |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
+------+
How to do it?
source
share