Thursday, 19 December 2013

Solution for repeating result in SQL

Solution for repeating result

 Arya P Ramesan

-----------------------------------------------------------

SQL query: SELECT p.job_post_id ,pl.location_id FROM tbl_employer_post_details p INNER JOIN tbl_employer_post_location pl ON p.job_post_id=pl.job_post_id LIMIT 0, 30 ;

Rows: 16

job_post_id
location_id
post1
LO1
post1
LO2
post1
LO3
post1
LO4
post2
LO3
post2
LO4
post2
LO1
post2
LO2
post3
LO2
post3
LO4
post4
LO5
post4
LO1
post5
LO1
post5
LO5
post6
LO3
post6
LO5

Solution


SQL query:
SELECT p.job_post_id ,GROUP_CONCAT(pl.location_id) location_ids FROM tbl_employer_post_details p INNER JOIN tbl_employer_post_location pl ON p.job_post_id=pl.job_post_id GROUP BY p.job_post_id LIMIT 0, 30 ;

Rows: 6

job_post_id
location_ids
post1
LO1,LO2,LO3,LO4
post2
LO3,LO4,LO1,LO2
post3
LO2,LO4
post4
LO5,LO1
post5
LO1,LO5
post6
LO3,LO5

No comments:

Post a Comment