I want to create a query in MySQL in the order table and check if it has a reservation identifier, if it does not have a booking_id identifier, it should be available in every way in the invoice table.
I want the return value to be boolean in one field.
Took the given example in
Case ID # 1 I expect immediate true because it is available
Case with identifier # 2 I expect that in the invoice table there will be a “slowed down” value, since non- all invoices have booking_id, it should return only true if invoice number 3 is actually a reservation identifier, that is, everything invoices have booking_id when order is not specified.
I tried several ways, but still couldn’t and I don’t even know how best to deal with it.
Thanks for your input in advance!
Table:
|----+------------+
| id | booking_id |
|----+------------+
| 1 | 123 |
| 2 | NULL |
|----+------------+
Table score:
+----+----------+------------+
| id | order_id | booking_id |
+----+----------+------------+
| 1 | 1 | 123 |
| 2 | 2 | 124 |
| 3 | 2 | NULL |
+----+----------+------------+
Scheme
CREATE TABLE IF NOT EXISTS `invoice` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`order_id` int(11) NOT NULL,
`booking_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
)
CREATE TABLE IF NOT EXISTS `order` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`booking_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
source
share