I'm having a problem in MySQL query.
I need MySQL query to display the following output and I also need to take CSV or Excel or PDF report.
id | nos ------------- 1 12,13,14 2 14 3 14,12
id | values ------------ 12 raja 13 rames 14 ravi
I want output like this:
id | values --------------------- 1 raja, rames, ravi 2 ravi 3 ravi, raja
In SQL, it's better to store a single value in a column, not a comma-separated list of values. See my answer to Is storing a comma separated list in a database column really that bad?
You can try this query, but it will be terribly slow and inefficient:
SELECT Table1.id, GROUP_CONCAT(Table2.values) AS values
FROM Table1
JOIN Table2 ON FIND_IN_SET(Table2.id, Table1.nos)
GROUP BY Table1.id;
See the FIND_IN_SET() function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With