andyhajime Posted October 8, 2009 Share Posted October 8, 2009 Hey guys... I never did this before and not sure if it's possible. I need some advise for y'all the experts. I've this task from a certain client and what he wants is - to list out all the comments within the website database onto a page, sort them out via latest date entry. Sound simple right? Actually, to me it's not. There are like over 5 modules in the website - eg: Blog, Gallery, Videos, ect. ...and each module has it's own table for comments to be stored. - if comments posted in the gallery, it will be stored in "data_gallerycomment" - if comments posted in the blog, it will be stored in "data_blogcomment" - if comments posted in the video, it will be stored in "data_videocomment" All the comments entries are separated/organized into it's own personal table. I noticed the columns on the comment tables are no difference for the other comment tables. All have id, name, email, text, ip and date. I figured that it's still possible to query the comments since the columns are replicates of one another. Only thing is I don't know how. I know how to query a single table and ORDER BY date DESC or ASC, that sort of stuff. But to query a multiple tables at one time, that's beyond my IQ level in php. Appreciate if you guys gimme some advised on how to do this. If it's not possible then it's ok. Quote Link to comment https://forums.phpfreaks.com/topic/176977-solved-sqlquery-from-3-or-more-tables-and-sort-them-out-according-to-time-stamp/ Share on other sites More sharing options...
taquitosensei Posted October 8, 2009 Share Posted October 8, 2009 Let's say you want to get all the comments. Regardless of who posted them select * from data_gallerycomment UNION select * from data_blogcomment UNION select * from data_videocomment order by date Quote Link to comment https://forums.phpfreaks.com/topic/176977-solved-sqlquery-from-3-or-more-tables-and-sort-them-out-according-to-time-stamp/#findComment-933120 Share on other sites More sharing options...
andyhajime Posted October 8, 2009 Author Share Posted October 8, 2009 UNION... today I learn a new method. Is there any difference between UNION ALL and UNION? Just some random question for personal general knowledge.. Anyway, problem solved. Thanks for the assistance man. Quote Link to comment https://forums.phpfreaks.com/topic/176977-solved-sqlquery-from-3-or-more-tables-and-sort-them-out-according-to-time-stamp/#findComment-933139 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.