0

I have 2 Mysql tables :

station :

enter image description here

logger :

enter image description here

Using this sql query it's showing following result :

$getStation = mysqli_query($conn, "SELECT st.st_tbl_id, st.st_name, st.st_address, st.st_lat, st.st_long, st.created,
GROUP_CONCAT(lg.lg_name) AS lg_name 
FROM station AS st 
LEFT JOIN logger AS lg ON lg.lg_id = st.lg_id 
GROUP BY st.st_name, st.st_id, st.lg_id 
ORDER BY st.st_tbl_id DESC");

enter image description here

Here you can see station name is duplicate value but it's should be unique one. Like for this scenario it's should be Comilla and Dhaka

shibbir ahmed
  • 1,014
  • 2
  • 18
  • 34

2 Answers2

0

See https://stackoverflow.com/a/2421441/347565

In your case, those entries have different lg_id, so they won't be grouped together. I think you just change your query to only group by st.st_id and you'll get the results you want.

Community
  • 1
  • 1
Matthieu
  • 16,103
  • 10
  • 59
  • 86
0

Try this:

$getStation = mysqli_query($conn, "SELECT st.st_name, st.st_address, st.st_lat, st.st_long, st.created,
GROUP_CONCAT(lg.lg_name) AS lg_name 
FROM station AS st 
LEFT JOIN logger AS lg ON lg.lg_id = st.lg_id 
GROUP BY st.st_name,st.st_address,st.st_lat, st.st_long, st.created");
Jibin Balachandran
  • 3,381
  • 1
  • 24
  • 38