sql - Complex MySQL query from 4 tables -
So far, I have not been successful in my quest on the combination of 4 tables. I have 4 tables:
Content
content_id | Source_id | Content_title | Content_date ------------------------------------------------- ------- 1 | 1 | Factory | 189982398300 2 2 | Cold and cloudy | 189982398299 3 2 | Green tea | 189982398298
source
source_id | Source_name ------------------- 1 | BBC2 | Reuters
Settings
settings_ id | Setting_name ------------------------------- 1 | BBC_Iplayer_string2 | Reuters_video_ id3 | Reuters_category
content_join_settings
content_id | Settings_id | Settings_data ------------------------------------------ 1 | 1 | Js88sdhjsd0gDS09 2 | 2 | Video_8AJK3ADJD8 2 | 3 | Weather 3 | 2 | Video_K7KD8N2ND9 3 | 3 | Food and Drink
So as you've already considered every material record, its source is linked to its own source, and comes with additional settings depending on the source is. In BBC posts, there is a BBC_Iplayer_string
, and in Reuters post, there are Reuters_video_id
and a reuters_category
. Of course this is just an example.
I want to combine the result, and as a column name with setting_name
, I'm not sure how to explain it, I will show it to:
content_id | Source_name | Content_title | Content_date | BBC_Iplayer_string | Reuters_video_id | Reuters_GATE ------------------------------------------------- -------------------------------------------------- ----- 1 | BBC Factory | 189982398300 | Js88sdhjsd0gDS09 | Faucet Zero 2 Reuters | Cold and cloudy | 189982398299 | Faucet Video_8AJK3ADJD8 | Weather 3 | Reuters | Green tea | 189982398298 | Faucet Video_K7KD8N2ND9 | Food & Drink
I am not very skilled in complex MySQL queries. I do not know where to start, what to find alone. I started with this question, but I do not know how to continue. I probably can not even stop
Select content from the
You need to join tables, and then smoke the results to move the rows into columns.
select c.content_id, s.source_name, c.content_title, c.content_date, MAX (case settings_name when 'bbc_iplayer_string' occurssetting_data end) as bbc_iplayer_string, MAX (CASE setting_name Join source_id = c .source_id INNER as a source of render_video_id, MAX (CASE setting_name when 'reuters_category' then settings_data END) as reuters_category contents as C in the form of INNER content_join_settings WHEN 'reuters_video_id' settings_data AS Cjs.content_id = cnsontent_id cnsontent_id at st.setting_id = cjs.setting_id GROUP c.content_id
Comments
Post a Comment