0

I have the following tables:

Dataentry
---------
name
id

DataentryRows
----------
id
dataentry_id


Fields
----------
dataentry_id
name
id

DataentryValue
----------
id
value
field_id
dataentry_row_id

I want to create a query to retrieve all the DataentryRows of a dataentry, where a DataEntryRow should includes all the fields name and the specific value.

The issue I am facing is that the number of fields is dynamic and I want to produce a column for each field of a dataentry.

Example data: http://sqlfiddle.com/#!9/9c1f66

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
Kerby82
  • 4,934
  • 14
  • 48
  • 74
  • SQL is not designed to return a variable number of columns. So simply select rows and turn them into columns in a loop in your app. – Thorsten Kettner Nov 12 '21 at 22:04
  • you can do it with prepared sql. post the data on http://sqlfiddle.com/ and the result that you want then i writes a query for you – Bernd Buffen Nov 12 '21 at 22:14
  • Well I definitely not need this for my app, I need to provide access to the db with a query. – Kerby82 Nov 12 '21 at 22:14
  • @BerndBuffen done, schema and sample data are on http://sqlfiddle.com/#!9/9c1f66/ – Kerby82 Nov 12 '21 at 22:26
  • cant open i. its empty – Bernd Buffen Nov 12 '21 at 22:29
  • http://sqlfiddle.com/#!9/9c1f66 @BerndBuffen is working for me – Kerby82 Nov 12 '21 at 22:41
  • @Kerby82 - now its also working for me. Can you please give me two more things. 1. what your desired result looks like with at least 2 rows to see if and which values ​​are below each other and 2. a simple query to get the result row by row to see how you join. You can attach this to your question or send it to me by e-mail (profile) – Bernd Buffen Nov 13 '21 at 06:37

0 Answers0