0

result of a join query-

SELECT st_stock.name, st_stock.price, 
       FORMAT(st_stock.quantity,0), 
       st_stock.exp_date, 
       admin.username 
FROM `st_stock` 
  INNER JOIN `admin` ON FIND_IN_SET(admin.ID,st_stock.broker_id) AND st_stock.id='2'

Sample Data

name        price     asjdb       exp_date            username
5.HK (HSBC) 74.40 HKD 100,000,000 2018-07-27 17:00:00 broker2
5.HK (HSBC) 74.40 HKD 100,000,000 2018-07-27 17:00:00 broker3

Expected Output

 5.HK (HSBC) 74.40 HKD 100,000,000 2018-07-27 17:00:00 broker2,broker3

2 Answers2

0

You did not specify the SQL engine you are using. When it comes to more advanced aggregate and windowing functions, implementations vary across database engines.

In PostgreSQL for example, you would use the string_agg aggregate function:

SELECT name, price, asjdb, exp_date, string_agg(username,',') AS username
FROM d
GROUP BY name, price, asjdb, exp_date;

For other database engines you would use:

  1. Oracle: LISTAGG
  2. SQL Server: STRINGAGG
  3. MySQL: GROUP_CONCAT

Further Reading: ListAGG in SQLSERVER

Zerodf
  • 2,208
  • 18
  • 26
0

If this is sql,

 SELECT st_stock.name, st_stock.price, 
           FORMAT(st_stock.quantity,0), 
           st_stock.exp_date, 
           GROUP_CONCAT(admin.username)
    FROM `st_stock` 
      INNER JOIN `admin` ON FIND_IN_SET(admin.ID,st_stock.broker_id) AND st_stock.id='2' GROUP BY st_stock.name
varman
  • 8,704
  • 5
  • 19
  • 53
  • @SmritimayDebnath its workign fine,right? Make sure you to click up arrow to vote good ans :D – varman Jul 11 '18 at 14:05