sql - MySQL JOIN two tables (Union) -


i have 2 mysql tables

first 1 booking

+------------+--------------+---------+ | id         | contact_no   | date    |  +------------+--------------+---------+ | p1         | 7898787946   | 15-06-05| | p1         | 7897891562   | 15-06-05| | p1         | 1546879585   | 15-06-07| | p2         | 1789546528   | 15-06-07| | p3         | 7894668265   | 15-06-07|  +------------+--------------+---------+ 

second 1 setup

+------------+--------------+------+-----+ | id         | date         | time | max | +------------+--------------+------+-----+ | p1         | 15-06-06     | 8.00 | 20  | | p1         | 15-06-07     | 8.00 | 20  | | p2         | 15-06-07     | 9.00 | 10  | | p3         | 15-06-08     | 8.00 | 20  |  +------------+--------------+------+-----+ 

i need join 2 tables particular id(let's p1) , wanted generate table. count number of rows particular date , id. (e.g count 15-06-05 of p1 2)

+------------+--------------+------+-----+ | count      | date         | time | max | +------------+--------------+------+-----+ | 2          | 15-06-05     | null | null| | 0          | 15-06-06     | 8.00 | 20  | | 1          | 15-06-07     | 8.00 | 20  | +------------+--------------+------+-----+ 

what mysql query can used generate third table

i tried select count(booking.date) 'count', setup.time, booking.date, setup.max booking left join setup on booking.date =setup.date , booking.id=setup.id , booking.id='p1' group booking.date order booking.date asc"

something this, can not check @ moment. pain without full joins in mysql:

select coalesce(id1, id2), coalesce(date1, date2), count(*), max(time), max(max)     (select b.id id1, s.id id2, b.date date1, s.date date2, s.time, s.max booking b      left join setup s on b.id = s.id , b.date = s.date      b.id = 'p1'      union      select b.id id1, s.id id2, b.date date1, s.date date2, s.time, s.max booking b      right join setup s on b.id = s.id , b.date = s.date      s.id = 'p1') t group coalesce(id1, id2), coalesce(date1, date2) 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -