0

I'm searching for the best way to display parent and child entries in one row. There can be more children per parent. Example:

PARENT Table:

P_ID P_VALUE
1 ABLE
2 BRUCE
3 CARL

CHILD TABLE:

C_ID P_ID C_VALUE
1 1 QUIL
2 1 YEN
3 2 MAT

OUTPUT REQUIRED:

P_ID P_VALUE C_ID1 C_VALUE1 C_ID2 C_VALUE2 ----C_IDn
1 ABLE 1 QUIL 2 YEN -----n
2 BRUCE 3 MAT NULL NULL ------n
3 CARL NULL NULL NULL NULL ------n
Thom A
  • 88,727
  • 11
  • 45
  • 75
  • 1
    Welcome to Stackoverflow. I think, "pivot" could help you. See here for example: https://stackoverflow.com/questions/7674786/how-can-i-return-pivot-table-output-in-mysql – h.m.i.13 May 28 '22 at 10:52
  • As @h.m.i.13 mentioned, you need to research on 'pivot' or 'cross tabulation' approaches for getting your desired output. T-SQL and MySQL approach would be very different to tackle this. Be ready to spend considerable time to study :) – nazim May 28 '22 at 11:04
  • Thank you for your response, but i need a dynamic way that works with multiple child details. For 1 p_id, number of c_id is not fix. – SAYAN DAS GUPTA May 28 '22 at 11:12
  • which RDBMS are you using? MySQL,SQL Server,postgresql,..... . tag it correctly – RF1991 May 28 '22 at 12:27
  • I've gone ahead and removed the conflicting tags. [Edit] your question to retag the RDBMS you are *really* using. SSMS (SQL Server Management Studio) and MySQL don't mix. – Thom A May 28 '22 at 15:25

0 Answers0