Display mysql results in one row -


mysql> select * facts; +----+---------+------------+---------+ | id | fact_id | fact_value | host_id | +----+---------+------------+---------+ |  1 |       1 | rh5        |       1 | |  2 |       1 | rh4        |       2 | |  3 |       2 | virtual    |       1 | |  4 |       2 | virtual    |       2 | |  5 |       3 | rack 2     |       1 | +----+---------+------------+---------+  mysql> select * hosts; +---------+-----------+ | host_id | host_name | +---------+-----------+ |       1 | bellagio  | |       2 | mirage    | +---------+-----------+ 

the query used following:

mysql> select host_name,fact_value hosts left join facts b on       >   b.host_id=a.host_id , b.fact_id in (1,2,3);  +-----------+------------+ | host_name | fact_value | +-----------+------------+ | bellagio  | rh5        | | bellagio  | virtual    | | bellagio  | rack 2     | | mirage    | rh4        | | mirage    | virtual    | +-----------+------------+ 

i want results print 1 row each host, notice how prints each fact_value on separate row. reason why have in clause table has on 40 possible columns each host. want handful (i select 3 in example).

here's i'm looking for.

+-----------+--------+-----------+-----------+ | host_name | value1 |  value 2  |  value 3  | +-----------+--------+-----------+-----------+ | bellagio  | rh5    |  virtual  |  rack 2   | | mirage    | rh4    |  virtual  |  null     | +-----------+--------+-----------+-----------+ 

select group_concat(fact_value)... ... group host_name 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -