How to concretize a stateful address in mysql
I am trying to concatenate an entire stateful address, suppose I have a string with the same state and a different address, so I want to run a Query that will fetch something like
state | Address
Maharastra ABC,DEF,XYZ
DELHI | WRU
currently my table
username | state | Address
abc Maharastra ABC
abc Maharastra DEF
abc Maharastra XYZ
abc DELHI WRU
def Maharastra ABC
def Maharastra OVU
def GOA IKL
def DELHI WRU
what i tried
SELECT address,state from location where username='abc' GROUP BY state
and my conclusion
address state
ABC Maharastra
WRU DELHI
+3
source to share
1 answer
GROUP_CONCAT()
is what you are looking for
SELECT STATE, GROUP_CONCAT(Address ORDER BY Address SEPARATOR ',')
FROM location where username='abc'
GROUP BY STATE
+3
source to share