Quick Tip – Your MySQL Query is too long? Use MySQL Views!
If yours MySQL query starts be too long like this: 🙂
SELECT `mdg_date_tab17` AS select `mdg_albums`.`id` AS `id`,`mdg_albums`.`date_add` AS `date_add`,'galeria' AS `typ`,`mdg_albums`.`album_desc` AS `tab_content`,(select concat(`mdg_auth_user_details`.`name`,' ',`mdg_auth_user_details`.`lastname`) from `mdg_auth_user_details` where (`mdg_auth_user_details`.`user_id` = `mdg_albums`.`who_add`)) AS `tab_author`,NULL AS `file`,NULL AS `tab_art_title`,NULL AS `tab_art_content`,`mdg_albums`.`album_name` AS `album_name`,`mdg_albums`.`url_name` AS `album_url`,(select group_concat(`mdg_photos`.`photo_filename` separator ',') from `mdg_photos` where (`mdg_photos`.`album_id` = `mdg_albums`.`id`) group by `mdg_photos`.`album_id`) AS `photo_filename` from `mdg_albums` union all select `mdg_ankieta`.`id` AS `id`,`mdg_ankieta`.`date_add` AS `date_add`,'testy sprawdzające' AS `typ`,`mdg_ankieta`.`coment` AS `tab_content`,(select concat(`mdg_auth_user_details`.`name`,' ',`mdg_auth_user_details`.`lastname`) from `mdg_auth_user_details` where (`mdg_auth_user_details`.`user_id` = `mdg_ankieta`.`who_add`)) AS `tab_author`,`mdg_ankieta`.`cat` AS `file`,`mdg_ankieta`.`name` AS `tab_art_title`,`mdg_ankieta`.`maxtime` AS `tab_art_content`,`mdg_ankieta`.`users_vote` AS `album_name`,NULL AS `album_url`,NULL AS `photo_filename` from `mdg_ankieta` union all select `mdg_ankieta3`.`id` AS `id`,`mdg_ankieta3`.`date_add` AS `date_add`,'testy powtórkowe' AS `typ`,`mdg_ankieta3`.`coment` AS `tab_content`,(select concat(`mdg_auth_user_details`.`name`,' ',`mdg_auth_user_details`.`lastname`) from `mdg_auth_user_details` where (`mdg_auth_user_details`.`user_id` = `mdg_ankieta3`.`who_add`)) AS `tab_author`,NULL AS `file`,`mdg_ankieta3`.`name` AS `tab_art_title`,`mdg_ankieta3`.`maxtime` AS `tab_art_content`,`mdg_ankieta3`.`users_vote` AS `album_name`,NULL AS `album_url`,NULL AS `photo_filename` from `mdg_ankieta3` union all select `mdg_ankieta2`.`id` AS `id`,`mdg_ankieta2`.`date_add` AS `date_add`,'efektywne czytanie' AS `typ`,`mdg_ankieta2`.`coment` AS `tab_content`,(select concat(`mdg_auth_user_details`.`name`,' ',`mdg_auth_user_details`.`lastname`) from `mdg_auth_user_details` where (`mdg_auth_user_details`.`user_id` = `mdg_ankieta2`.`who_add`)) AS `tab_author`,NULL AS `file`,`mdg_ankieta2`.`name` AS `tab_art_title`,`mdg_ankieta2`.`maxtime` AS `tab_art_content`,`mdg_ankieta2`.`users_vote` AS `album_name`,NULL AS `album_url`,NULL AS `photo_filename` from `mdg_ankieta2` union all select `mdg_arts`.`id` AS `id`,`mdg_arts`.`date_add` AS `date_add`,'ciekawe' AS `typ`,`mdg_arts`.`coment` AS `tab_content`,(select concat(`mdg_auth_user_details`.`name`,' ',`mdg_auth_user_details`.`lastname`) from `mdg_auth_user_details` where (`mdg_auth_user_details`.`user_id` = `mdg_arts`.`who_add`)) AS `tab_author`,`mdg_arts`.`category_id` AS `file`,`mdg_arts`.`title` AS `tab_art_title`,`mdg_arts`.`short_content` AS `tab_art_content`,`mdg_arts`.`content` AS `album_name`,NULL AS `album_url`,NULL AS `photo_filename` from `mdg_arts` union all select `mdg_downloads`.`id` AS `id`,`mdg_downloads`.`date_add` AS `date_add`,'do pobrania' AS `typ`,`mdg_downloads`.`coment` AS `tab_content`,(select concat(`mdg_auth_user_details`.`name`,' ',`mdg_auth_user_details`.`lastname`) from `mdg_auth_user_details` where (`mdg_auth_user_details`.`user_id` = `mdg_downloads`.`who_add`)) AS `tab_author`,`mdg_downloads`.`file` AS `file`,`mdg_downloads`.`category` AS `tab_art_title`,NULL AS `tab_art_content`,NULL AS `album_name`,NULL AS `album_url`,NULL AS `photo_filename` from `mdg_downloads` union all select `mdg_calendar`.`id` AS `id`,`mdg_calendar`.`date_add` AS `date_add`,'wydarzenia' AS `typ`,`mdg_calendar`.`title` AS `tab_content`,(select concat(`mdg_auth_user_details`.`name`,' ',`mdg_auth_user_details`.`lastname`) from `mdg_auth_user_details` where (`mdg_auth_user_details`.`user_id` = `mdg_calendar`.`who_add`)) AS `tab_author`,NULL AS `file`,`mdg_calendar`.`content` AS `tab_art_title`,`mdg_calendar`.`date` AS `tab_art_content`,NULL AS `album_name`,NULL AS `album_url`,NULL AS `photo_filename` from `mdg_calendar` union all select `mdg_ankieta5`.`id` AS `id`,`mdg_ankieta5`.`date_add` AS `date_add`,'testy pamięciowe' AS `typ`,`mdg_ankieta5`.`coment` AS `tab_content`,(select concat(`mdg_auth_user_details`.`name`,' ',`mdg_auth_user_details`.`lastname`) from `mdg_auth_user_details` where (`mdg_auth_user_details`.`user_id` = `mdg_ankieta5`.`who_add`)) AS `tab_author`,NULL AS `file`,`mdg_ankieta5`.`name` AS `tab_art_title`,`mdg_ankieta5`.`maxtime` AS `tab_art_content`,`mdg_ankieta5`.`users_vote` AS `album_name`,NULL AS `album_url`,NULL AS `photo_filename` from `mdg_ankieta5` where (`mdg_ankieta5`.`active` = 1) union all select `mdg_ankieta4`.`id` AS `id`,`mdg_ankieta4`.`date_add` AS `date_add`,'efektywne czytanie engramistrz' AS `typ`,`mdg_ankieta4`.`coment` AS `tab_content`,(select concat(`mdg_auth_user_details`.`name`,' ',`mdg_auth_user_details`.`lastname`) from `mdg_auth_user_details` where (`mdg_auth_user_details`.`user_id` = `mdg_ankieta4`.`who_add`)) AS `tab_author`,NULL AS `file`,`mdg_ankieta4`.`name` AS `tab_art_title`,`mdg_ankieta4`.`maxtime` AS `tab_art_content`,`mdg_ankieta4`.`users_vote` AS `album_name`,NULL AS `album_url`,NULL AS `photo_filename` from `mdg_ankieta4` where (`mdg_ankieta4`.`active` = 1);
then use MySQL Views, type in PhpMyAdmin SQL Query:
CREATE VIEW name_of_virtual_table AS ...this...select...above... ;
Now you can use your new view almost like normal table,
SELECT * FROM name_of_virtual_table ORDER BE date DESC
almost because you can’t DELETE, UPDATE, INSERT 🙂
Greetings!