MySQL Forums
Forum List  »  General

Parent child relationship questions
Posted by: Duncan Hill
Date: July 24, 2022 05:13AM

I have two related tables:

- device_id
- device_name
- device_type

- device_id
- event_type
- event_date

One to many relationship: device_id

I have two questions that I would like some advice on:

1. How should I insert records into the device_details & device_events? The first insert will require inserts into both tables but subsequent inserts will only insert into device_events. There needs to be some sort of 'if exists' condition on the device_details table.

2. I need to select all records from device_details along with only the last/most recent device_events record, then filter the results using event_type. What's the most efficient way to achieve this?

Thanks for any help, as can be seen my SQL skills is extremely limited.

Options: ReplyQuote

Written By
Parent child relationship questions
July 24, 2022 05:13AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.