You have two tables with a one to many join based on a field named id. You need to find records in the parent table that are not represented in the child table. how would you accomplish this?



You have two tables with a one to many join based on a field named id. You need to find records in t..

Answer / Dhanvendra Shukla

To find records in the parent table that are not represented in the child table, you can use a LEFT JOIN with a condition for NULL on the child table. Here's an example using SQL Server:

```sql
SELECT p.* FROM ParentTable AS p
LEFT JOIN ChildTable AS c ON p.id = c.id
WHERE c.id IS NULL;
```

In this query, a LEFT JOIN is performed between the parent and child tables. The WHERE clause filters out the rows where the id in the child table is NULL, which means those records are not present in the child table.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More DB Development Interview Questions

How can you log an error to the server event log from a stored procedure?

1 Answers  


I HAVE A PI ON COL A THE NEXT DAY I WANT CHANGE THE PI ON COL B? PLS SEND ME THE ANS

1 Answers   IBM,


How can you fix a poorly performing query?

1 Answers  


What you can do to remove data from the cache and query plans from memory for testing the performance of a query repeatedly?

1 Answers  


What are the 18 schemas?

1 Answers  


Explain about the relational database?

1 Answers  


What are cursors? Explain different types of cursors?

6 Answers  


Can you have a nested transaction?

1 Answers  


What is the difference between a primary index and a secondary index? What is a duplicate data entry in an index? Can a primary index contain duplicates?

5 Answers   IBM,


What is the maximum length of an extended property?

1 Answers  


Write the fastest query to find out how many rows exist in a table?

1 Answers  


what is difference between primary key and unique key ?

2 Answers  


Categories