SQL join column within 1 table
I'm busy with a script to display transactions.
I want to write a SQL query that sets everything on one line.
Here is the SQL:
SELECT transactienummer, code
FROM gb_kaarten
ORDER BY transactienummer DESC
LIMIT 4
this is the result:
transactienummer code
43141 1600
43141 4410
43141 1513
43141 1514
I just want to have a line that looks like this:
transactienummer code
43141 1600 4410 1513 1514
I've tried some joins, but I don't seem to get it.
Thanks in forehand for the help
+3
source to share
3 answers
You can find it on SO Link below
fooobar.com/questions/2975 / ...
In your case find trying this
SELECT distinct [transactienummer]
,(STUFF((SELECT CAST(' ' + Code AS VARCHAR(MAX))
FROM Table
WHERE (transactienummer= Table.transactienummer)
FOR XML PATH ('')), 1, 2, '')) AS Code
FROM Table
Find a solution in the Fiddle http://sqlfiddle.com/#!6/f8339/1
0
source to share