Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    MYSQL


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Is Between Date More Efficient For Query?


PHP

//grab rows from yesterday
WHERE (month(articles.date) = month(now()) AND
dayofmonth(articles.date) = (dayofmonth(now())-1) AND
year(articles.date)=year(now()))





View Complete Forum Thread with Replies

Related Forum Messages:
Most Efficient Date Field Type For Selects?
I have searched this forum seeking the answer to this question, to no avail.

I am making an events diary that will have a lot of entries. Entries will be entered in all kinds of order, including multiple events spanning a year or so.

Even multiple events of the same type will be individual entries. (e.g. weekly chess club meeting every weds at 7pm will be 52 entries)

My question is : Which is the best format to store dates?

Native mysql date type
Integer timestamp
A.n.other?

I suppose a worst case scenario is imagine I want to generate a calendar for July (31 days) and I want to show how many events there are for each day.

1st July (13 events)
2nd July (22 events)

and so on ... it is possible that any given day could have up to 100 entries.

What in your opinion is the best column type to use and ss there any kind of Indexing I can use to speed up select by dates? Or any other tip or trick you'd be prepared to share with me?

View Replies !
How To Create Efficient MySQL Query From A Pseudo Query
I'm trying to build a webapplication where users can search for a person having a particular preference for color and material. To store this information I use the following structure (a MySQL dump can be found at the end of this post):
*table person with fields:
-persid: autoincrement id
-name: name of the person
*table material with fields:
-materialid: autoincrement id
-material: name of the material eg "wood"
*table color with fields:
-colorid: autoincrement id
-color: name of the color eg "green"
*table persmaterial with fields:
-persmatid: autoincrement id
-persid: link to table person
-materialid: link to table material
*table perscolor with fields:
-perscolorid: autoincrement id
-persid: link to table person
-colorid: link to table color

In the webapplication the search can be entered by the users as a kind of pseudo query:
(color=red OR color=blue) AND color=green AND material=iron

My question is: how can I automatically transform this pseudo query into an efficient MySQL query?
I have tried out some different options:


Option 1:
(SELECT p.persid FROM person p, perscolor pc, persmaterial pm WHERE p.persid=pc.persid AND (pc.colorid=1 OR pc.colorid=2) AND p.persid=pm.persid AND pm.materialid=2 GROUP BY p.persid HAVING (count(DISTINCT pc.colorid)=2 AND count(DISTINCT pm.materialid)=1)) UNION
(SELECT p.persid FROM person p, perscolor pc, persmaterial pm WHERE p.persid=pc.persid AND (pc.colorid=2 OR pc.colorid=3) AND p.persid=pm.persid AND pm.materialid=2 GROUP BY p.persid HAVING (count(DISTINCT pc.colorid)=2 AND count(DISTINCT pm.materialid)=1))
Remarks:
*I do not see how to turn a general pseudo query into a query like the one in option 1, except for turning the pseudo query into a sum of products form where the sulms would correspond to the UNIONs. IS there a clever way to obtain such a sum of products form from an arbitrary pseudo query?


Option 2:
SELECT persid FROM person p WHERE
(EXISTS(SELECT * FROM perscolor pc WHERE pc.colorid=1 AND p.persid=pc.persid)
OR
EXISTS(SELECT * FROM perscolor pc WHERE pc.colorid=3 AND p.persid=pc.persid))
AND
EXISTS(SELECT * FROM perscolor pc WHERE pc.colorid=2 AND p.persid=pc.persid)
AND
EXISTS(SELECT * FROM persmaterial pm WHERE pm.materialid=2 AND p.persid=pm.persid)
Remarks:
*very easy to get from pseudo query to MySQL query but what about performance?

Option 3:
SELECT p.persid FROM person p, perscolor pc, persmaterial pm WHERE
p.persid=pc.persid
AND
(pc.colorid=1 OR pc.colorid=2 OR pc.colorid=3)
AND p.persid=pm.persid
AND pm.materialid=2
GROUP BY p.persid HAVING
sum(case when pc.colorid in (Ƈ',Ɖ') then 1 else 0 end) >= 1
AND
sum(case when pc.colorid=ƈ' then 1 else 0 end)>=1
AND
sum(case when pm.materialid=ƈ' then 1 else 0 end)>=1
Remarks:
*this option requires the pseudo query to be turned into a product of sums form; again is their a clever way to obtain such a form;




Option 4
SELECT DISTINCT pc1.persid FROM perscolor pc1
INNER JOIN perscolor pc2
ON pc1.persid=pc2.persid AND pc2.colorid=2
INNER JOIN persmaterial pm1
ON pc1.persid=pm1.persid AND pm1.materialid=2
LEFT OUTER JOIN perscolor pc3
ON pc1.persid=pc3.persid AND pc3.colorid=1
LEFT OUTER JOIN perscolor pc4
ON pc1.persid=pc4.persid AND pc4.colorid=3
WHERE COALESCE(pc3.persid,pc4.persid) IS NOT NULL
Remarks:
*this option requires the pseudo query to be turned into a product of sums form

Option 5:
SELECT p.persid FROM person p, persmaterial pm,perscolor pc1,perscolor pc2,perscolor pc3 WHERE p.persid=pm.persid AND p.persid=pc1.persid AND p.persid=pc2.persid AND p.persid=pc3.persid AND (pc1.colorid=1 OR pc2.colorid=3) AND pc3.colorid=2 AND pm.materialid=2 GROUP BY p.persid
Remarks:
*very easy to get from pseudo query to MySQL query but what about performance?



-- phpMyAdmin SQL Dump
-- version 2.6.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Oct 19, 2006 at 01:13 PM
-- Server version: 4.1.9
-- PHP Version: 4.3.10
--
-- Database: `aston`
--

-- --------------------------------------------------------

--
-- Table structure for table `color`
--

CREATE TABLE `color` (
`colorid` int(11) NOT NULL auto_increment,
`color` varchar(30) NOT NULL default '',
PRIMARY KEY (`colorid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

--
-- Dumping data for table `color`
--

INSERT INTO `color` VALUES (1, 'red');
INSERT INTO `color` VALUES (2, 'green');
INSERT INTO `color` VALUES (3, 'blue');
INSERT INTO `color` VALUES (4, 'yellow');

-- --------------------------------------------------------

--
-- Table structure for table `material`
--

CREATE TABLE `material` (
`materialid` int(11) NOT NULL auto_increment,
`material` varchar(30) NOT NULL default '',
PRIMARY KEY (`materialid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `material`
--

INSERT INTO `material` VALUES (1, 'wood');
INSERT INTO `material` VALUES (2, 'iron');

-- --------------------------------------------------------

--
-- Table structure for table `perscolor`
--

CREATE TABLE `perscolor` (
`perscolorid` int(11) NOT NULL auto_increment,
`persid` int(11) NOT NULL default Ɔ',
`colorid` int(11) NOT NULL default Ɔ',
PRIMARY KEY (`perscolorid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;

--
-- Dumping data for table `perscolor`
--

INSERT INTO `perscolor` VALUES (1, 1, 1);
INSERT INTO `perscolor` VALUES (2, 1, 2);
INSERT INTO `perscolor` VALUES (3, 2, 1);
INSERT INTO `perscolor` VALUES (5, 3, 3);
INSERT INTO `perscolor` VALUES (6, 3, 2);

-- --------------------------------------------------------

--
-- Table structure for table `persmaterial`
--

CREATE TABLE `persmaterial` (
`persmatid` int(11) NOT NULL auto_increment,
`persid` int(11) NOT NULL default Ɔ',
`materialid` int(11) NOT NULL default Ɔ',
PRIMARY KEY (`persmatid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

--
-- Dumping data for table `persmaterial`
--

INSERT INTO `persmaterial` VALUES (1, 1, 1);
INSERT INTO `persmaterial` VALUES (2, 1, 2);
INSERT INTO `persmaterial` VALUES (3, 2, 1);
INSERT INTO `persmaterial` VALUES (5, 3, 2);

-- --------------------------------------------------------

--
-- Table structure for table `person`
--

CREATE TABLE `person` (
`persid` int(11) NOT NULL auto_increment,
`name` varchar(30) NOT NULL default '',
PRIMARY KEY (`persid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

--
-- Dumping data for table `person`
--

INSERT INTO `person` VALUES (1, 'john');
INSERT INTO `person` VALUES (2, 'emily');
INSERT INTO `person` VALUES (3, 'liz');

View Replies !
Which Is More Efficient? One Big Query Or Lots Of Little Queries?
Which is more efficient/faster/better?

running one big query with lots of joins, or lots of little queries in a loop?

so:

1.) one big query:

select cat.*, subcat.* from cat join subcat on ...
or

select * from cat

while $row = $cat_result->fetch()
select * from subcat where catid = $row['catid']
????

View Replies !
Slow Query->Efficient Query
I have a query that is running really slow !!!!
I have joined on Key fields and indexed the tables fully but it is still solw.
--------------------------------------------

select d.id, a.signed, u.Forename, u.Surname, d.paid, p.date, d.payment, p.amount, d.acctual
from details d
join poten a
on a.id = d.id
left join recieved p
on d.id = p.id
left join users u
on a.signed = u.userid
where d.paid > '01-Dec-2005'
and d.authorrceived is not null
and d.authorrefused is null
and ((d.payment starting 'E' or
d.payment starting 'e') or
(d.payment starting 'Q' or
d.payment starting 'q' and
p.target = '500'))
order by d.paid, a.signed, d.id

View Replies !
Date Query (how Do I Get Everything With A Date In 7 Days?)
the goal is a reminder email to people who have a workshop coming up in 7 days.

So, workshop date is 2006-05-25.
The reminder email should go out on 2006-05-18

I guess mysql query returns all records where (Date column - 7 days) = current date. Right?

But what does teh QUERY look like? And how does it accomodate if today is 2006-05-28 and the upcoming workshop is 2006-06-04 (so month changes over the 7 day period).

View Replies !
What's The Most Efficient Way?
I've done a database scheme and wonder what the most efficient way of storing certain entries would be. The site will have news, reviews and tutorials and these will be under the same categories. So I'm wondering what the best way to do design the database scheme would be.

Have one table like I've done now in the "content" table with the posibilty to differentiate the entries with the "post_type" field or have three different tables? Below is the table "content".

Field Type Null Default
post_id int(10) No
post_date datetime No 0000-00-00 00:00:00
post_text text No
post_title text No
post_cat_id int(4) No 0
post_description text No
post_name varchar(200) No
post_type int(4) No 0

View Replies !
How Efficient Is In() , And How Much Is The Most That You Should Put In An In()?
I am just wondering as to the efficiency of the in() function in MySQL.

select field1,field2,...,fieldn from table where id in(1,2,3,4,5,6, ... , n);

assuming:
id is an indexed field.
table is a VERY big table (100 000+ - 1 million+ records)

what do you think is the largest number of values you could pass to the in() function without completly flattening your server?

View Replies !
Most Efficient YES/NO...
I)
Table_A has fields Data_1, Data_2, Data_3, and Data_4; I need to determine whether value 'X' is present (at least once) in any of the Data_N fields. All I need is a YES/NO answer: YES, 'X' is present (at least once) in one of the Data_N fields of Table_A [Record number(s) not required!], or NO, 'X' is not present in any of the Data_N fields in any of the records in Table_A.

II)
Similar scenario, but this time Table_A has fields RecID, Data_1, Data_2, Data_3, and Data_4. I need to determine the RecID (none, one, or more) of every record that has value 'X' in any of the Data_N fields.

I'm looking for the query that will be fastest and most elegant to implement.

View Replies !
Quickest And Most Efficient
i run an online game. I want to give each user a ranking, based on how high thier score is.If for example, i had 20,000 players, i dont want to have to update them all one by one, it may strain the server and take a long time.
Is there another way i can assign a rank number (rank 1 has the top score and so on)

View Replies !
Efficient UPDATE
I have a table with the following structure;

CREATE TABLE my_table
(
id_1 int(11) NOT NULL ,
id_2 int(10) NOT NULL ,
stauts tinyint(1) NOT NULL DEFAULT 0 ,
PRIMARY KEY (id_1)
) Engine =InnoDB';


The table currently has arround 100,000 entries. When I try to run variations of the following statement it is taking around 4 seconds per query;

UPDATE IGNORE my_table
SET id_1 = 74240, id_2 = 5

I need it to be running a lot faster than 4 seconds per query as I need to update upwards of 100,000 records a day! My server is fairly beefy, a 3 gig dual core opeteron and is generaly running below 1.0 load.

View Replies !
Better Key, More Efficient Indexing
I have a complex query that uses UNION and I want to make this query use indexes for faster execution. Code:

View Replies !
Efficient Tables.
I am starting out on a project where I need to store GPS information. The data consists largely of a series of "Points" each consisting of a longitude,latitude and elevation.

On a typical "route" there could be hundreds of points.

My question is how can I efficiently store this information. It does not sound sensible to normalise this and add hundreds of rows to a table for each "route".

Sample data is along the lines of :

- <trkpt lat="54.016942977905273" lon="-1.4903640747070313">
<ele>82.330078125</ele>

<time>2006-09-03T07:35:41Z</time>

</trkpt>


- <trkpt lat="54.016938870772719" lon="-1.490332055836916">
<ele>0</ele>

<time>2006-09-03T07:35:42Z</time>

</trkpt>


View Replies !
Efficient Storage Of IP Address
I am establishing a database for the purpose of logging access to my secure
webserver and am wanting to make the database as efficient as I can because
it will be doing a lot of work when the site goes live.

What is the most efficient way in a MySQL table to store remote IP
addresses? What data type should I use? Should I just go with a basic
VARCHAR(15) to allow for 4 sets of 3 digits with 3 decimal separators, or is
there a better way?

View Replies !
Efficient Placement Of Fields
is there any noticable efficiency is ordering the position of the field
types?. Like say i place the join keys in a table at the end, and varchars
and text at the top of the table does it really matter?

Also when i do a query like select * from table where id IN (1), where 1 is
usually a primary key int is that quicker than doing where id=1 or is there
no difference and is it handling the int as a string or as an int?

View Replies !
Efficient Database Structure
I have been developing a new website and i need help in deciding the best database structure for it. The site is basically a dating website with various modules like blogs, videos, comments, friends, photos etc. I have created a member table that stores all the basic profile info and created seperate tables for friends, photos, messages, blogs etc and MemberID as foreign key. Now on profile page, i want to display all info related to member like his profile info, his photos, friend list, messages etc and i have to execute 7-10 short queries on profile page for this. Also, i think Joins will not be much helpful as there is one to many relationship e.g there can be more than 1 photo for a member and i am saving each photo in a seperate record. Similar is the case for other tables?

View Replies !
Creating An Efficient Database
i'm currently writing a web based catalogue system in php using a mysql database.

the catalogue has a number of products in it from different brands.

i would like to know if it is more efficient to have each brand in a separate table then a "master" table just listing the brand name and corresponding table

or

all the products in one large table and a "master" table listing each brand in the large table. the large product table would of course have a field to state which brand the product was from.

the efficiency would be based on users being able to access the database via html browsers using php and also search the database.

View Replies !
How To Make Index Most Efficient
I have a large table (> 3,000,000 records). Each records contain a primary key like 'id' and a lots of attributes like 'age', 'department'. I want to build some indices
to accelerate my query.

I read the document which says that too many indices may slow down the INSERT and UPDATE operations. So is there any rule on how to set indices in such table? If I create an index for every field, would that be a very bad idea? If I create an index on each of two fields but not on their combination, will the indices contribute to queries on the combination?

View Replies !
Efficient Way To Count Rows
I'm trying to get the number of rows in a table with a very large number of records in it (~9 million). When I run a select count(*) for some criteria (where name='something', etc) it takes around 6-8 secs for the query to return the value. I tried by using SQL_CALC_FOUND_ROWS with a very small LIMIT but then the query was taking even longer.

I'm using InnoDB, with query caching enabled. I could look at the information_schema and get the approximate row count but whenever I use a where clause it'll be way off mark.

View Replies !
Efficient Way Of Mass Indexing?
I have been working on a program that will populate and index a database. The populating doesn't take too long, but the indexing does. My question is: Is there a better approach to indexing this table than the one I'm using right now?

I'm doing this through QtSql. headers is a QString array of 48 column names I want to index.

for (int i = 0; i < headers.size(); ++i) {
q.exec("ALTER TABLE mysqltable ADD INDEX(" + headers[i] + ");");
}

example run for 20000 rows:
viper,david $ time ./main -r 20000
Database Connection Established
0.520u 0.060s 0:21.27 2.7% 0+0k 0+0io 0pf+0w

View Replies !
Is This INSERT With SELECT As Efficient As Possible?
I'm writing a pretty complex web app and will be repeating many times over a query very similar to below and need to know if there is a more efficient way to do it. If anyone has input, I'd be happy to hear:

INSERT INTO table (somecolumn) VALUES ((SELECT id FROM other_table WHERE foo = 'bar'))

View Replies !
Is This An Efficient MySQL Setup?
I would like to offload the MySQL server from my dedicated box in order to speed up page loads.

I don't have an additional dedicated server so my only option is to get a VPS.
But is offloading the MySQL server to a VPS, albeit a modest one, even worthwhile?

I understand this is a very broad question because I am not providing any details but that being the case I am expecting a broad answer

View Replies !
Efficient Way To Left Join?
What is the most efficient way to do a table join, but even if there is no matching foreign key, still return the table on the left.

SELECT col, col2, COUNT(col3)
FROM tbl1 t1
LEFT JOIN tbl2 t2
ON t1.id = t2.id
GROUP BY t1.id

But this only works if there is a matching foreign key on t2, I would like all t1 rows to return regardless of whether they exist on t2 or not.

View Replies !
Most Efficient Way To Extract Limited Data
I am currently using the following code, is it the most efficient way to extract and sort the 6 items from the database. The database currently holds over 2,500,000 rows and I want to extract the data as efficiently and quickly as possible. Code:

View Replies !
Most Efficient, Stable Version Of MYSQL?
We're still using mysql 3.23.56, so it's time to upgrade! It has never once crashed on us, so we've been content with it so far. However, some of the inefficient query optimizations make us want to upgrade.

Does anyone know what the current most efficient and stable version of MYSQL is? We don't require views or cursors or stored procedures or any of that... Just whatever's the most reliable and best optimized for fast query execution of fairly simple SQL.

I know that 3.23 has some issues with using indices correctly during optimization (most notably in ORDER BY ... DESC). Is that problem fixed in 4?

View Replies !
How To Query Date Between?
I have table name "actionlog",and one field in there is "date_time"
date_time (Type:datetime) example value : 11/1/2006 11:05:07

if I'd like to query date between 24/07/2006 to 26/07/2006(I don't
need time),how to write SQL command?

select * from actionlog where date_time 24/07/2006 AND date_time <
24/07/2006 ??

View Replies !
Query For A Date
I want to select records that have an expiration date of 1 month before the current date on.
The query looks something like this:
SELECT first_name, last_name
FROM members
WHERE exp_date >
The exp_date is stored as a UNIX timestamp.

View Replies !
Efficient Ways To Retrieve Specific Rows.
My site used forum software that I wrote myself (in Perl) which, up until
now, has used flat files. This worked fine, however lately I've been wanting
to do more stuff with user accounts, and had been eying MySQL for over a
year.
Finally I've decided to start off small by converting the forum's account
system to a MySQL database (and convert the rest later after I'm
comfortable). So far everything is working fine, and I've figured out how to
create the table, insert records, modify records, and so on.
However I had a question on what was the most efficient way to retrieve
information about a user as I read through the flat file containing
messages.
As each message is read I want to find that user's relevant information,
build it into my output, then continue on to the next message. Now here's my
problem. Since I'm reading a flat file in a way that was once trying to be
somewhat memory efficient (on really slow server way back when, trying to
avoid arrays and hashes) I'm finding that I'm having to send separate
questions to MySQL as each message comes up. Say from 1 to 20 very simple
questions to complete printing the page. Also, sometimes the questions might
be repetitive - since I'm not storing any of the results in memory, if a
user appears twice I ask about it twice.
Would I really be better off trying to find a way to consolidate all
distinct users into a single question? Or is MySQL efficient enough that
this isn't really much of a concern?

View Replies !
Efficient String Compare To A Group Of Values
(Post edited to change "WHERE field = options" to "WHERE field IN options").

I have a website using PHP and MySQL 5.0; the database holds personal names, addresses and various information. Right now I'm building a query which checks whether a person lives in a certain group of UK counties.

I've got arrays set up in PHP which hold the groups of counties, and I've dynamically created a "group" from each array. So, in PHP,

$county_array = array('Kent','Surrey','London','Essex','...');
$county_group gets set to "('kent','surrey','london','essex',...)"

Each group may hold perhaps 20 individual counties.

Now, for my database query, I use:

$query = "SELECT ... WHERE lower(county) IN $county_group";

Is the "WHERE field IN (a|b|c|d|e|...)" a slow comparison in MySQL? Is there a more efficient way to do it? Is this something that stored procedures can help me with?

View Replies !
The Most Efficient Manner To Update Multiple Rows
I have a table that holds information about people
The table is quite large (300,000 rows)
I need to write code that update many of the rows in the table

Here is what I need to do
Two of the fields that I store about each person are: location and country
The location is some free text which the user can type in, while the country is the ISO country code, like "US", "ES" and so on

I need go over all the records in the database, and for those that have a non-empty location field, to extract the value and to try to guess what country the user is from and to update the Country field accordingly

My problem is that I might find that most of the records need updating, and this might lead to 100,00+ update statements

I cannot use LOAD DATA as this is product database

Is there a way to update multiple rows (each with a different value and condition in a single query?

View Replies !
Efficient SELECT From Multiple Tables With Same Formatting?
Let's say I have 2 tables with the exact same formatting (field/column names, etc) -- the only difference is the name of the tables.. one is called "table1" the other is called "table2"

If I wanted to query both of the together is this legal and good coding practice?

"SELECT id, headline, permalink, body FROM table2007_11, table2007_12 WHERE id=23"

understandly I get this error: Column 'id' in field list is ambiguous"

is there a better way to do this than printing out each table name for each field individually? (ie. id. table2007_11, id. table2007_12, etc)?

View Replies !
Efficient Country/Province City Setup
I currently have a program that does a global query of all of the data. I want to break it down so as to drill the user down to thier local area. for example:

Country
Province
Region
City

As you can see, a country can have many provinces, a province many regions and a region many cities or a province many cities. What is the most effecinet way to do this in MySql? I'm OK with doing single tables. ie:
INSERT INTO Province VALUES (NULL, 'Ontario', 'ON');
but I'm unclear if that's the way it should be done. I'm using PHP on the client side.

View Replies !
Most Efficient Way Of Storing Data From Multiple Accounts
As part of a system I am putting together I need to allow users to create thier own accounts on my servers. Each user can create their own account, and then have their users register for it. Each account needs it data seperate from the others, a member registered for one account should not be able to view another account and a username registered with one account should still be available to the other accounts.

The ways I have been looking at are:

1. Create a new database for every account created so that all users are kept in seperate databases.

2. Have one table for users, one for topics, one for posts etc and then associate each row within this table with the relevent account. So for example a user could register with the forum with the ID 4, so their user entry would be

Userid: 234
Username: xxxx
Password: xxxx
Forumid: 4

Then when a new member registers with any account I simply check that there is not another user with the same account ID and username. Indexes on relevent fields in this system could help speed up huge tables.

I expect to quickly have 20,000 plus accounts (and in theory it could go up to hundreds of thousands).

I guess my question is which of these methods is better from a speed point of view once we get a large number of accounts and users. Also, are there restrictions on the number of fields in a table that could cause problems?

Using MySQL by the way, on an Apache server.

View Replies !
Date To Days Query
I need to update one of our mysql tables, which has about 60,000 entires and
correct the amount of days remain on each data record. An example of one of the
data entires is:


memid days regdate expdate
--------------------------------------
625290 | 5 | 2003-07-15 | 2003-08-16

now the days should be 14 and not 5 days. I have been trying to update the table
with a single SQL query but haven't come up with a way to do this.. I'm sure
it's something simple but I can't seem to come up with it. What is the best way
to accomplish this in a single query to update the entire table so all the
"days" are accurate according to the "expdate", and change the "days" so they
are correct?

View Replies !
Latest-date Query
I am trying to get all records that share the most recent "RatesUpdated" datetime value from 1 table. I am doing the below query and I keep getting the following syntax error: "#1111 - Invalid use of group function"
SELECT t1.Product, max(t2.RatesUpdated) FROM `lqdp_mortgage_rates` t1, `lqdp_mortgage_rates` t2
WHERE t1.RatesUpdated = max(t2.RatesUpdated)
group by max(t2.RatesUpdated)

View Replies !
Join Query By Date
I've these tables:
- PERSON (id,name,age,....)
- EXAM (id,date,note,exam_type,id_user)

One person has 0 or more exams.

I have to do this report:

name, age, date, note, exam_type

This looks easy, but I have to list for each person, his/her LAST EXAM GIVEN. I mean, only the last exam must be shown for each person, and well, if person has no exam yet... to show blank (if possible)

View Replies !
Date Query Question
I have found myself in a situation where I lost data for two days, well not exactly lost but I need to insert the data between that day and the current day.
for example...I need to insert between records 2005-05-03 and 2005-05-06. Is there any way to do this or does the insert statement always append at the end?

View Replies !
Two Where Date Clauses In Query
I'm trying to teach myself sql and am struggling on getting a query to work.
Basically, i want to find all records listed after a certain date, but so long as they don't already exists before another date.

For instance, it should do something like:

SELECT * from table
WHERE date > "2006-06-20"
BUT don't display if there are date entries < "2006-06-19";

So, if there are values in the table with a date after the 20th June that don't have any entries before the 19th June then they will be displayed.

View Replies !
Query Date Range
I have a Date/Time field that has a date and time as the data in the field, in a table that I want to run a query on returning records that are in a date range.

What would the select statement be to return the records in the date range just by date so any record in that date range will be returned regaurdless of its time?

View Replies !
Search Query By Date
I'm trying to adjust an older search query to perform a search by date where the date column is an INT field (unix date stamp).

SELECT * FROM incidents WHERE date < DATE_ADD (CURDATE(), INTERVAL $searchDate DAY);

Where date, formally a DATE field, is now an INT(11) field. $searchDate is an int, indicating how many days back to search. 1 (day), 5 (days), etc.I'm assuming mysql's DATE_ADD function is specific to the DATE field. How can I achieve the same result, but with an INT field?

View Replies !
Select Query (date)
How would I set the WHERE condition to select the fileds below to select only those who were placed 2 years ago?

mysql> SELECT placement_date, name, age
-> FROM table1
-> WHERE


View Replies !
SQL Date Range Query
I need some help with this one. I hate admitting defeat but I'm getting frustrated!

I've got a table called 'Events' with these fields...

eID
eName
eStartDate
eEndDate

An example entry would be...

1
'Course Open Day'
12-Nov-2006
14-Nov-2006

What I want to be able to do is search the table and select any records where a given date falls between the the startDate and endDate.

So, if I searched with &#3913;-Nov-2006' i'd get 'Course Open Day'.


View Replies !
Date Search Query Help
I'm trying to filter my search results by date. The field name I'm running this for is final_date and is a DATE field.

I want my results to show records that have sales_reps.final_date within the past 30 days.

Query:

SELECT
sales_reps.sr_id,
sales_reps.name,
sales_reps.job_number,
sales_reps.status,
sales_reps.stage,
UNIX_TIMESTAMP(sales_reps.final_date) as final_date,
UNIX_TIMESTAMP(sales_reps.date_to_shop) as date_to_shop,
shop_orders.community,
users.user_id,
u.fname,
u.lname,
users.builder,
users.division,
ei.shop_result,
ei.good_tape,
sa.shopper_id,
shop_orders.order_id,
UNIX_TIMESTAMP(shop_orders.date) as order_date,
pi.fname as pfname,
pi.lname as plname ,
ei.exit_id
FROM sales_reps
LEFT JOIN shop_orders ON sales_reps.order_id=shop_orders.order_id
LEFT JOIN users ON users.user_id=shop_orders.builder_id
LEFT JOIN report_types ON report_types.type_id=sales_reps.report_type
LEFT JOIN shop_assignments as sa ON sa.sr_id=sales_reps.sr_id
LEFT JOIN exit_interviews as ei ON ei.shop_id=sa.shop_id
LEFT JOIN users as u ON u.user_id=sa.shopper_id
LEFT JOIN users as pi ON pi.user_id=sa.pi_id
WHERE DATE_SUB(CURDATE(), INTERVAL 30 DAY) <=UNIX_TIMESTAMP(sales_reps.final_date)
AND (sales_reps.status = 'Completed' OR sales_reps.status = 'Rejected')
ORDER BY users.builder, users.division, community ASC, final_date ASC
Is this:

WHERE DATE_SUB(CURDATE(), INTERVAL 30 DAY) <=UNIX_TIMESTAMP(sales_reps.final_date)
incorrect?

I'm getting dates such as 2007-03-22 and 2007-03-19 in my result set and they shouldn't be there.

Could I get some pointers?

View Replies !
Most Efficient Way To Import Large Data Dump From Phpmyadmin?
I have a large data dump (export) from phpmyadmin my client just gave me - 200k - .

What's the most efficient way to import that into a new database? The new db has not defined tables since that is part of the phpmyadmin export.



View Replies !
Delete Query Date Formatting
I have several queries that I need to run that delete records based on a date field. One of the queries is

Code:

DELETE FROM `tbl_trade_accept_ctoons` WHERE `trade_id` in (select trade_id from tbl_trade_accept where accepted_date < '2009-02-14*');

However, the 'accepted_date' field saves values as the long timestamps like "1234571139". In the current setup, it always comes up with 0 records. How do I modify my query to be able to find the dates I want to clear out is the field it needs to target is formatted differently?

View Replies !
Select Query Within Specified Date Range..?
Im doing a select in which im specifying the date range..

"select key_id from result where started_at_date >= '2008-10-17 13:30:00' and ended_at_date <= '2008-10-17 13:30:20'"

but in the above query im getting the key_id for which the date range is out of the date range specified here.

That is im getting key_id = 5, for whcih started_at = '2008-10-18 13:30:00' and ended_at = '2008-10-18 13:30:20'

View Replies !
How To Create A Query To Get Top 5 Item For Each Date
I have running out of idea on hw to create a query to get each day top 5 item with a date range given more than 1 month or more.

meant: if i have a date range from 2006-01-23 to 2006-10-23, then i want to get the latest 31 days data only with each day TOP 5 item. How?

Lets say i have a table with this keyword: MyDate;Item;CountItem;

The date range is unknown and can be any range selected by user.

I am trying to think of put auto increament for each day with CountItem desc and each day the column of auto-increament is set to 5 only so at last i can just get all the data from it. But the question is i dunno how to do it?

Anyone have better solution? I know if using store procedure then can do this but is it can done without store prodedure?

View Replies !
Query Date Interval Question
I have used MySQL for quite some time but have just recently started making more advanced queries. I hope someone can help me with this.

The problem is this: I have a table of Orders with Price, Date, Salesman and ID. To get the total sales of one user for say week 2 or February is not very hard, that would be something like:
SELECT SUM(Price) AS SumPrice
FROM Order
WHERE OrderDate BETWEEN "2007-02-01" AND "2007-02-28" AND Salesman="Bob"
GROUP BY Salesman

The problem now is that I would like to have a result with like weeks 1-10 or Jan-May, with each week or month and its correspongding SUM on a separate row. Can anyone help me and say what is missing please? I reckon that my query above would be a subquery in a larger query specifying the intervals, but I can't figure out how to do it.

View Replies !
Query - Count With Date Intervals
I have this:

select count(*) from visitors
where visitordate >= '2008-01-01'
AND visitordate >= '2008-01-08'

Now this gives me a count of how many visitors that week visited my site but I want something more automatic. I do not know which functions to use to make this logic below happen:

Start with year base (ie:2008) increment by week number (ie:upto 52) and determine how many visitors each week visited the site.

I wish this worked:

select count(*) from visitors
where visitordate = week(1), then week(2), etc.

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved