Reputation: 75
I'm having trouble with a SQL query and I was wondering if any one of you could use a little of your time to help me.
I have the following query
SELECT
cfd_enc.id,
cfd_enc.version,
cfd_enc.prefijo,
cfd_enc.fecha,
cfd_enc.cfd,
cfd_enc.no_aprobacion,
cfd_enc.tipo_comprobante,
cfd_det.id_orden,
cfd_det.producto,
cfd_det.total
FROM cfd_parametros,cfd_enc LEFT JOIN cfd_det ON cfd_enc.id=cfd_det.id_orden
which gets me this:
(I have 6 rows in cfd_det that share id_orden with cfd_enc.id)
Is there any way I could combine all the repeated rows to get something like this?
Any help is really appreciated. I'm really stuck, so let me know if you need more specific information.
Upvotes: 2
Views: 178
Reputation: 1205
Good question - this type of problem actually comes up quite often. It looks like what you're trying to do is 'pivot' rows into columns. Similar questions have been asked/answered elsewhere on SO:
SQL Server 2005, turn columns into rows
How to transform rows to columns
Upvotes: 5