Node.js Nested MySQL Queries for Beginner

I have two nested sql queries:

  1. SELECT * FROM events
  2. SELECT * FROM photos WHERE event = ?

Table events (id, name, description, startDate, endDate) Table photos (id, name, url, eventId)

Tables relationship between events and photos is one-to-many. For one event we can have many photos.

With first query I obtain all events from my db. With second query I need to obtain output for each result of first query event's photos.

I need to use only MySQL module.

Thanks.

For sequential query execution in NodeJS you will need to execute next query in the success callback of previous one, thus it would be sequential.

Good to know > To avoid callback hell there is very useful async library where you can use waterfall or series workflow to avoid nesting callbacks.

Once you get the result of first query, use the recursive function to fire the second query and every time you call that function you can pass the events value one by one.