Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL join column within 1 table

Tags:

sql

php

mysql

Im busy with a script to display transactions.

I want to write an SQL query which sets everything on one line.

Here is the SQL :

SELECT transactienummer, code
FROM gb_kaarten 
ORDER BY transactienummer DESC
LIMIT 4

this is the output :

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 have tried some joins, but i dont seem to get it.

Thanks in forehand for the help

like image 724
Joop Schoolse Avatar asked Sep 02 '26 05:09

Joop Schoolse


1 Answers

I assume that you are using mysql, you should do something like this:

SELECT transactienummer, GROUP_CONCAT(string SEPARATOR ' ') 
FROM gb_kaarten
GROUP BY code;

Pay attention that you will have all the result in one field separated by ''

like image 160
teoreda Avatar answered Sep 03 '26 20:09

teoreda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!