LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-10-2009, 07:27 AM   #1
hattori.hanzo
Member
 
Registered: Aug 2006
Posts: 168

Rep: Reputation: 15
running a mysql query by date on more than 1 table?


I have a mysql database with a few tables. I need to run queries by date (24 hour period) on more than 1 table. How do people usually set this up in the backend.

Is it possible to query more than 1 table at a time using a wildcard character for the table name? for example all tables which start with 2006-*.

I read somewhere that it would be better to setup views. Would it be possible to setup a view for each 'day' extracting date from the timestamp field then I just run the query on that day's view?

thanks
 
Old 03-10-2009, 02:10 PM   #2
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Quote:
Originally Posted by hattori.hanzo View Post
I have a mysql database with a few tables. I need to run queries by date (24 hour period) on more than 1 table. How do people usually set this up in the backend.

If you extract the same data from all tables, you can use a union:
Code:
SELECT start_date FROM table1 UNION
SELECT start_date FROM table2 UNION
SELECT start_date FROM table3
ORDER BY blah
Which give you a number of rows consisting of one column start_date.

Quote:
Originally Posted by hattori.hanzo View Post
Is it possible to query more than 1 table at a time using a wildcard character for the table name? for example all tables which start with 2006-*.
No

Quote:
Originally Posted by hattori.hanzo View Post
I read somewhere that it would be better to setup views.
A view is a sort of predefined query. But you can treat it as a table, that is, once you execute a query you get a table with results. In a view you can select from that table.

Quote:
Originally Posted by hattori.hanzo View Post
Would it be possible to setup a view for each 'day' extracting date from the timestamp field then I just run the query on that day's view?
thanks
It is unclear what you mean here. But you can run a query on a view.

jlinkels
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql replication: Error running query on master: Access denied; RKris Linux - Software 1 06-19-2011 04:14 PM
LXer: The Multi-Table Query Generator using phpMyAdmin and MySQL LXer Syndicated Linux News 0 02-18-2009 08:01 AM
How do I INSERT IGNORE the current date into a table in MYSQL? resetreset Programming 9 12-15-2008 01:39 AM
MySQL :: Table in query adds significant delay lackluster Programming 7 07-10-2004 03:48 AM
Changing date format in MySQL table vous Linux - Software 8 09-03-2003 06:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration