View Single Post
Old 09-22-2004, 09:37 AM  
psili
Confirmed User
 
Join Date: Apr 2003
Location: Loveland, CO
Posts: 5,526
Database smarties -- SELECT on index help

MySQL question as I can't find my answer in the manual and what I try and make up doesn't seem to work.

Basically, here's my table schema:


id = int(4) auto_increment
name = varchar(20)
date_live = datetime

I created an index on the date_live field:

CREATE INDEX date_live ON table (date_live);


Now, my problem is I want to use that index when I run a query against the table, but i only want to select the "date" element and not both "date" and "time" from the "date_live" field -- like a wildcard:

explain select * from table where date_live like '2004-09-22%'

Unfortunately that query doesn't seem to use the index.

This query doesn't work, because some rows have a time element and I need those rows too:

explain select * from table where date_live = '2004-09-22'

Anyone know how to query for just the DATE on a DATETIME field that can use the index I created on it ?
__________________
Your post count means nothing.
psili is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote