Jump to content

[SOLVED] SQLQuery from 3 or more tables and sort them out according to time stamp.


Recommended Posts

Hey guys...

I never did this before and not sure if it's possible.  :shrug:

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.

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 

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.