mysql - How can I write a query to aggregate multiple strings into one field? -


i trying merge 3 tables. first table has id , data_name, second table data_id, option_id , property, third table user_id, data_id.

for example:

first table +----+-----------+ | id | data_name | +----+-----------+ | 1  + veri1     | | 2  + veri2     | | 3  + veri3     | +---++-----------+  second table  +----------+----------+-----------+ data_id    | property | option_id | +----------+----------+-----------+ | 1        | blue     | 1         | | 1        | cold     | 2         | | 2        | gray     | 1         | | 2        | hot      | 2         | | 3        | green    | 1         | | 3        | cold     | 1         | +----------+----------+-----------+  third table +----------+-----------+ | user_id  | data_id   | +----------+-----------+ | 1        | 2         | | 2        | 3         | | 3        | 1         | +----------+-----------+ 

i want get:

user: 1 data: veri2 properties: gray - hot 

how write sql this?

first start clause. data stored want?

from user_first_table join property_second_table join user_data_third_table 

then consider conditions should join (i find easier re-order tables)

from user_data_third_table t  join user_first_table f on f.id = t.user_id join property_second_table s on s.data_id = t.data_id 

then narrow down clause, e.g. want data veri1

from user_data_third_table t  join user_first_table f on f.id = t.user_id join property_second_table s on s.data_id = t.data_id f.data_name = 'veri1' 

then label fields of data want

select f.id 'user', f.data_name 'data', s.property 'properties' user_data_third_table t  join user_first_table f on f.id = t.user_id join property_second_table s on s.data_id = t.data_id f.data_name = 'veri1' 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -