Join two tables in MYSQL and avoid duplicate values
Do this &quot;deduplication&quot; on the application side. It will be much easier to clean up repetitive values with PHP or JS. It is possible to make what you want by UDVs but SQL wasn't intended for it.