dimanche 24 avril 2016

Least Popular Event - Get list of events where bookings IS NULL OR LEAST

I have two Tables : Events and Bookings One Event has Many Bookings

Event          Bookings
  1               1
  1               2
  1               3
  2               //consider this as no row in bookings table
  3               4
  3               5
  3               6
  4  

I need to get list of events that have no bookings, that is there is no foreign key reference of events_id in bookings table. so here Event 2 and 4. If all the events have some bookings then the one with least bookings shows up.

$query = select E.id, E.name, count('B.event_id') as totalbookings from events E, bookings B where E.id = B.event_id group by B.event_id; Gets me list of all events and total bookings for events with some bookings.

How do I get the events data which don't have bookings at all?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire