Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-07-2008, 10:15 AM
Michael Stearne
 
Posts: n/a
Default Query/Key Optimization

Hi.

The main table for our site is called properties and it gets hit quite
often (several times per second) something like:

Queries Total: 41,496 Avg/Sec: 6.89 Slow: 0
Cache Hits : 15,096 Avg/Sec: 2.51 Now/Sec: 0.00 Ratio: 36.38%
Threads Total: 1 Active: 1 Cached: 76
Key Efficiency: 94.41% Bytes in: 114 Bytes out: 6,713

This properties table is very simple. (Pasted below) There is about
500,000 rows in the table and we are experiencing long queries like:

SELECT * FROM properties WHERE 1 =1 AND properties.Published <>0 AND
properties.Deleted <>1 AND properties.state = 'ca' AND TYPE =
'Residential' AND Image1 <> '' ORDER BY id DESC LIMIT 0 , 35

An explain on that yields:

| id | select_type | table | type | possible_keys
| key | key_len | ref | rows | Extra
|
+----+-------------+------------+-------------+-----------------------------+-----------------+---------+------+-------+---------------------------------------------------------------+
| 1 | SIMPLE | properties | index_merge |
Type,TypeSubType,StateIndex | Type,StateIndex | 1,67 | NULL | 45048
| Using intersect(Type,StateIndex); Using where; Using filesort |

Is there anything you can see with the table or key design that might
be causing this slowdown? There are 5 databases: 1 master, 4 slaves
replicated. The master is only used for INSERTs, UPDATEs and DELETEs.
The properties table is INNODB. Should it me MyISAM?

Thanks for any help!
Michael


CREATE TABLE properties (
id int(11) unsigned NOT NULL auto_increment,
UserID int(11) unsigned NOT NULL default '0',
`Type` enum('Commercial','Residential') NOT NULL default 'Residential',
Subtype varchar(64) NOT NULL default '0',
Zip varchar(10) default '',
Heading varchar(84) NOT NULL default '',
Address1 varchar(128) NOT NULL default '',
Address2 varchar(32) default NULL,
Unit varchar(32) default NULL,
Neighborhood varchar(64) default NULL,
City varchar(64) NOT NULL default '0',
State varchar(64) default '',
Country varchar(4) default 'USA',
.....
.......
.......
ListingContactHTML varchar(255) default NULL,
IsShare tinyint(1) default '0',
IsSublet tinyint(1) default '0',
PRIMARY KEY (id),
KEY `Type` (`Type`),
KEY Subtype (Subtype),
KEY TypeSubType (`Type`,Subtype),
KEY CityHood (City,Neighborhood),
KEY GoogleBase (GoogleBase),
KEY Zip (Zip),
KEY AddressSearch (Heading,Zip,City,Neighborhood,Address1,Unit),
KEY StateIndex (State),
KEY ListingContactRemoteCode (ListingContactRemoteCode),
KEY LeaseType (LeaseType),
KEY CreationDate (CreationDate),
KEY LastMapLookup (LastMapLookup),
KEY UserID (UserID),
KEY Country (Country),
KEY LatLon (lat,lon),
KEY CityStateType (City,State,`Type`),
KEY BatchUpdateRemoteListingID (BatchUpdateRemoteListingID),
KEY CountryType (Country,`Type`),
KEY Country_2 (Country,City,State)
) ENGINE=InnoDB AUTO_INCREMENT=907758 DEFAULT CHARSET=latin1
AUTO_INCREMENT=907758 ;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-07-2008, 10:15 AM
Michael Stearne
 
Posts: n/a
Default Re: Query/Key Optimization

As a note. The query itself may not be taking long but there are many
"Sorting result " and "Copying to tmp table " in myTop.

Thanks,
Michael



On Tue, May 6, 2008 at 3:26 PM, Michael Stearne <mstearne@entermix.com> wrote:
> Hi.
>
> The main table for our site is called properties and it gets hit quite
> often (several times per second) something like:
>
> Queries Total: 41,496 Avg/Sec: 6.89 Slow: 0
> Cache Hits : 15,096 Avg/Sec: 2.51 Now/Sec: 0.00 Ratio: 36.38%
> Threads Total: 1 Active: 1 Cached: 76
> Key Efficiency: 94.41% Bytes in: 114 Bytes out: 6,713
>
> This properties table is very simple. (Pasted below) There is about
> 500,000 rows in the table and we are experiencing long queries like:
>
> SELECT * FROM properties WHERE 1 =1 AND properties.Published <>0 AND
> properties.Deleted <>1 AND properties.state = 'ca' AND TYPE =
> 'Residential' AND Image1 <> '' ORDER BY id DESC LIMIT 0 , 35
>
> An explain on that yields:
>
> | id | select_type | table | type | possible_keys
> | key | key_len | ref | rows | Extra
> |
> +----+-------------+------------+-------------+-----------------------------+-----------------+---------+------+-------+---------------------------------------------------------------+
> | 1 | SIMPLE | properties | index_merge |
> Type,TypeSubType,StateIndex | Type,StateIndex | 1,67 | NULL | 45048
> | Using intersect(Type,StateIndex); Using where; Using filesort |
>
> Is there anything you can see with the table or key design that might
> be causing this slowdown? There are 5 databases: 1 master, 4 slaves
> replicated. The master is only used for INSERTs, UPDATEs and DELETEs.
> The properties table is INNODB. Should it me MyISAM?
>
> Thanks for any help!
> Michael
>
>
> CREATE TABLE properties (
> id int(11) unsigned NOT NULL auto_increment,
> UserID int(11) unsigned NOT NULL default '0',
> `Type` enum('Commercial','Residential') NOT NULL default 'Residential',
> Subtype varchar(64) NOT NULL default '0',
> Zip varchar(10) default '',
> Heading varchar(84) NOT NULL default '',
> Address1 varchar(128) NOT NULL default '',
> Address2 varchar(32) default NULL,
> Unit varchar(32) default NULL,
> Neighborhood varchar(64) default NULL,
> City varchar(64) NOT NULL default '0',
> State varchar(64) default '',
> Country varchar(4) default 'USA',
> .....
> ......
> ......
> ListingContactHTML varchar(255) default NULL,
> IsShare tinyint(1) default '0',
> IsSublet tinyint(1) default '0',
> PRIMARY KEY (id),
> KEY `Type` (`Type`),
> KEY Subtype (Subtype),
> KEY TypeSubType (`Type`,Subtype),
> KEY CityHood (City,Neighborhood),
> KEY GoogleBase (GoogleBase),
> KEY Zip (Zip),
> KEY AddressSearch (Heading,Zip,City,Neighborhood,Address1,Unit),
> KEY StateIndex (State),
> KEY ListingContactRemoteCode (ListingContactRemoteCode),
> KEY LeaseType (LeaseType),
> KEY CreationDate (CreationDate),
> KEY LastMapLookup (LastMapLookup),
> KEY UserID (UserID),
> KEY Country (Country),
> KEY LatLon (lat,lon),
> KEY CityStateType (City,State,`Type`),
> KEY BatchUpdateRemoteListingID (BatchUpdateRemoteListingID),
> KEY CountryType (Country,`Type`),
> KEY Country_2 (Country,City,State)
> ) ENGINE=InnoDB AUTO_INCREMENT=907758 DEFAULT CHARSET=latin1
> AUTO_INCREMENT=907758 ;
>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-07-2008, 10:15 AM
Krishna Chandra Prajapati
 
Posts: n/a
Default Re: Query/Key Optimization

Hi
The query is not optimized as it is scanning 45048 rows.
Vertical partitioning can be used because there is a lot of column in single
table.

On Tue, May 6, 2008 at 3:26 PM, Michael Stearne <mstearne@entermix.com>
wrote:

> Hi.
>
> The main table for our site is called properties and it gets hit quite
> often (several times per second) something like:
>
> Queries Total: 41,496 Avg/Sec: 6.89 Slow: 0
> Cache Hits : 15,096 Avg/Sec: 2.51 Now/Sec: 0.00 Ratio: 36.38%
> Threads Total: 1 Active: 1 Cached: 76
> Key Efficiency: 94.41% Bytes in: 114 Bytes out: 6,713
>
> This properties table is very simple. (Pasted below) There is about
> 500,000 rows in the table and we are experiencing long queries like:
>
> SELECT * FROM properties WHERE 1 =1 AND properties.Published <>0 AND
> properties.Deleted <>1 AND properties.state = 'ca' AND TYPE =
> 'Residential' AND Image1 <> '' ORDER BY id DESC LIMIT 0 , 35
>
> An explain on that yields:
>
> | id | select_type | table | type | possible_keys
> | key | key_len | ref | rows | Extra
> |
>
> +----+-------------+------------+-------------+-----------------------------+-----------------+---------+------+-------+---------------------------------------------------------------+
> | 1 | SIMPLE | properties | index_merge |
> Type,TypeSubType,StateIndex | Type,StateIndex | 1,67 | NULL | 45048
> | Using intersect(Type,StateIndex); Using where; Using filesort |
>
> Is there anything you can see with the table or key design that might
> be causing this slowdown? There are 5 databases: 1 master, 4 slaves
> replicated. The master is only used for INSERTs, UPDATEs and DELETEs.
> The properties table is INNODB. Should it me MyISAM?
>
> Thanks for any help!
> Michael
>
>
> CREATE TABLE properties (
> id int(11) unsigned NOT NULL auto_increment,
> UserID int(11) unsigned NOT NULL default '0',
> `Type` enum('Commercial','Residential') NOT NULL default 'Residential',
> Subtype varchar(64) NOT NULL default '0',
> Zip varchar(10) default '',
> Heading varchar(84) NOT NULL default '',
> Address1 varchar(128) NOT NULL default '',
> Address2 varchar(32) default NULL,
> Unit varchar(32) default NULL,
> Neighborhood varchar(64) default NULL,
> City varchar(64) NOT NULL default '0',
> State varchar(64) default '',
> Country varchar(4) default 'USA',
> .....
> ......
> ......
> ListingContactHTML varchar(255) default NULL,
> IsShare tinyint(1) default '0',
> IsSublet tinyint(1) default '0',
> PRIMARY KEY (id),
> KEY `Type` (`Type`),
> KEY Subtype (Subtype),
> KEY TypeSubType (`Type`,Subtype),
> KEY CityHood (City,Neighborhood),
> KEY GoogleBase (GoogleBase),
> KEY Zip (Zip),
> KEY AddressSearch (Heading,Zip,City,Neighborhood,Address1,Unit),
> KEY StateIndex (State),
> KEY ListingContactRemoteCode (ListingContactRemoteCode),
> KEY LeaseType (LeaseType),
> KEY CreationDate (CreationDate),
> KEY LastMapLookup (LastMapLookup),
> KEY UserID (UserID),
> KEY Country (Country),
> KEY LatLon (lat,lon),
> KEY CityStateType (City,State,`Type`),
> KEY BatchUpdateRemoteListingID (BatchUpdateRemoteListingID),
> KEY CountryType (Country,`Type`),
> KEY Country_2 (Country,City,State)
> ) ENGINE=InnoDB AUTO_INCREMENT=907758 DEFAULT CHARSET=latin1
> AUTO_INCREMENT=907758 ;
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
> http://lists.mysql.com/mysql?unsub=p...tikc@gmail.com
>
>



--
Krishna Chandra Prajapati
MySQL DBA,
Ed Ventures e-Learning Pvt.Ltd.
1-8-303/48/15, Sindhi Colony
P.G.Road, Secunderabad.
Pin Code: 500003
Office Number: 040-66489771
Mob: 9912924044
URL: ed-ventures-online.com
Email-id: prajapatikc@gmail.com

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-07-2008, 06:20 PM
Andy Wallace
 
Posts: n/a
Default question about update/join query

Hey all -
I have two tables - an event_log table, and a user table. There is
a "last_visit" column in the user table, and I want to update it from
the event_log with the most recent event timestamp. And I want to do
it without a subquery, eventually, both these tables will be pretty
large, especially the event_log.

I tried this:

update enduser E join event_log EL on EL.enduser_acnt = E.enduser_acnt
set E.last_visit = MAX(EL.event_time)
group by EL.enduser_acnt

but I get an error on the group by. The pertinent tables sections are:

table event_log
event_time TIMESTAMP
enduser_acnt int

table enduser
enduser_acnt int
last_visit datetime

Any help appreciated. Thanks...
andy


--
Andy Wallace - CISData - IDX Slave
AIM: acmwallace awallace@cisdata.net
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 05-07-2008, 06:20 PM
Andy Wallace
 
Posts: n/a
Default Re: question about update/join query

Clarification: I DON'T want to update the last_visit field if there
is no matching event record...

I managed to get this to sort of work:

update enduser E
set E.last_visit = (select MAX(EL.event_time)
from event_log EL
where EL.enduser_acnt = E.enduser_acnt
group by EL.enduser_acnt);

but it updated the last_visit field to the default value if it found
no matching event_log row... which I don't want to happen.

thanks,
andy

Andy Wallace wrote:
> Hey all -
> I have two tables - an event_log table, and a user table. There is
> a "last_visit" column in the user table, and I want to update it from
> the event_log with the most recent event timestamp. And I want to do
> it without a subquery, eventually, both these tables will be pretty
> large, especially the event_log.
>
> I tried this:
>
> update enduser E join event_log EL on EL.enduser_acnt = E.enduser_acnt
> set E.last_visit = MAX(EL.event_time)
> group by EL.enduser_acnt
>
> but I get an error on the group by. The pertinent tables sections are:
>
> table event_log
> event_time TIMESTAMP
> enduser_acnt int
>
> table enduser
> enduser_acnt int
> last_visit datetime
>
> Any help appreciated. Thanks...
> andy
>
>


--
Andy Wallace - CISData - IDX Slave
AIM: acmwallace awallace@cisdata.net
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 05-07-2008, 06:20 PM
Neil Tompkins
 
Posts: n/a
Default Order Problem

Hi All,

I've the following query :SELECT ProductID FROM Products WHERE Enabled= 'Yes' AND ProductID IN(varProductID)

This query works fine. However the query result is in a different order towhat I passed in varProductID.

How can I order the results based on my list like

varProductID = "1000,2500,1500"

At the moment the result is

1000
1500
2500

But I want

1000
2500
1500

Thanks,
Neil


__________________________________________________ _______________

Discover and Win with Live Search

http://clk.atdmt.com/UKM/go/msnnkmgl...ukm/direct/01/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 05-10-2008, 02:03 PM
Andy Wallace
 
Posts: n/a
Default Re: question about update/join query

I want to put only the max date into the field... I was thinking that max
was a group function, but now that I type that out loud, perhaps I'm not
using all the neurons available... hmmm...


thanks,
andy

Martin wrote:
> Hi Andy-
>
> Is there a reason why you are using Query group by clause in UPDATE
> statement?
>
> M
> ----- Original Message ----- From: "Andy Wallace" <awallace@cisdata.net>
> To: "mysql list" <mysql@lists.mysql.com>
> Sent: Wednesday, May 07, 2008 1:07 PM
> Subject: Re: question about update/join query
>
>
>> Clarification: I DON'T want to update the last_visit field if there
>> is no matching event record...
>>
>> I managed to get this to sort of work:
>>
>> update enduser E
>> set E.last_visit = (select MAX(EL.event_time)
>> from event_log EL
>> where EL.enduser_acnt = E.enduser_acnt
>> group by EL.enduser_acnt);
>>
>> but it updated the last_visit field to the default value if it found
>> no matching event_log row... which I don't want to happen.
>>
>> thanks,
>> andy
>>
>> Andy Wallace wrote:
>>> Hey all -
>>> I have two tables - an event_log table, and a user table. There is
>>> a "last_visit" column in the user table, and I want to update it from
>>> the event_log with the most recent event timestamp. And I want to do
>>> it without a subquery, eventually, both these tables will be pretty
>>> large, especially the event_log.
>>>
>>> I tried this:
>>>
>>> update enduser E join event_log EL on EL.enduser_acnt = E.enduser_acnt
>>> set E.last_visit = MAX(EL.event_time)
>>> group by EL.enduser_acnt
>>>
>>> but I get an error on the group by. The pertinent tables sections are:
>>>
>>> table event_log
>>> event_time TIMESTAMP
>>> enduser_acnt int
>>>
>>> table enduser
>>> enduser_acnt int
>>> last_visit datetime
>>>
>>> Any help appreciated. Thanks...
>>> andy
>>>
>>>

>>
>> --
>> Andy Wallace - CISData - IDX Slave
>> AIM: acmwallace awallace@cisdata.net
>>
>> --
>> MySQL General Mailing List
>> For list archives: http://lists.mysql.com/mysql
>> To unsubscribe: http://lists.mysql.com/mysql?unsub=mgainty@hotmail.com
>>
>>

>


--
Andy Wallace - CISData - IDX Slave
AIM: acmwallace awallace@cisdata.net
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 05-10-2008, 02:03 PM
Andy Wallace
 
Posts: n/a
Default Re: question about update/join query

Ok, I think I need to try to restate my problem.

I have an event_log table, which tracks events (!). Basic structure
is:

table: event_log
event_time timestamp
event_id int
user_id int

and my user table:
table user
user_id int
name varchar(50)
last_visit datetime


I want to run a query that updates the last_visit column of user with
the MAX(event_time) row for which the user_id's match, but only if I
find an event:

update user U
set U.last_visit = (select max(L.event_time) from event_log L
where L.user_id = U.user_id

I would like to do it without a subquery, I thought that the
multiple table syntax for UPDATE would do it, but I can't wrap
my head around it.

UPDATE user U, event_log L
SET U.last_visit = MAX(L.event_time)
WHERE U.user_id = L.user_id
GROUP BY L.event_time

I guess the main question is - CAN I do this? Or will I have to resort
to either a subquery, or external processing?

thanks,
andy











Martin wrote:
> Hi Andy-
>
> the MAX function needs group by for the column for which it calculating
> max value as in this example
> (select MAX(EL.event_time)
> // from event_log EL
> // where EL.enduser_acnt = E.enduser_acnt
>
> //Inner join forces selection on columns which contain non null values
> as seen here
> from event_log AS EL INNER JOIN Event AS E
> ON EL.enduser_acnt = Event.enduser_anct
>
> group by EL.event_time);
> // group by EL.enduser_acnt);
>
> HTH
> Martin
> ----- Original Message ----- From: "Andy Wallace" <awallace@cisdata.net>
> To: "Martin" <mgainty@hotmail.com>
> Cc: "mysql list" <mysql@lists.mysql.com>
> Sent: Wednesday, May 07, 2008 6:21 PM
> Subject: Re: question about update/join query
>
>
>> I want to put only the max date into the field... I was thinking that max
>> was a group function, but now that I type that out loud, perhaps I'm not
>> using all the neurons available... hmmm...
>>
>>
>> thanks,
>> andy
>>
>> Martin wrote:
>>> Hi Andy-
>>>
>>> Is there a reason why you are using Query group by clause in UPDATE
>>> statement?
>>>
>>> M
>>> ----- Original Message ----- From: "Andy Wallace" <awallace@cisdata.net>
>>> To: "mysql list" <mysql@lists.mysql.com>
>>> Sent: Wednesday, May 07, 2008 1:07 PM
>>> Subject: Re: question about update/join query
>>>
>>>
>>>> Clarification: I DON'T want to update the last_visit field if there
>>>> is no matching event record...
>>>>
>>>> I managed to get this to sort of work:
>>>>
>>>> update enduser E
>>>> set E.last_visit = (select MAX(EL.event_time)
>>>> from event_log EL
>>>> where EL.enduser_acnt = E.enduser_acnt
>>>> group by EL.enduser_acnt);
>>>>
>>>> but it updated the last_visit field to the default value if it found
>>>> no matching event_log row... which I don't want to happen.
>>>>
>>>> thanks,
>>>> andy
>>>>
>>>> Andy Wallace wrote:
>>>>> Hey all -
>>>>> I have two tables - an event_log table, and a user table. There is
>>>>> a "last_visit" column in the user table, and I want to update it from
>>>>> the event_log with the most recent event timestamp. And I want to do
>>>>> it without a subquery, eventually, both these tables will be pretty
>>>>> large, especially the event_log.
>>>>>
>>>>> I tried this:
>>>>>
>>>>> update enduser E join event_log EL on EL.enduser_acnt = E.enduser_acnt
>>>>> set E.last_visit = MAX(EL.event_time)
>>>>> group by EL.enduser_acnt
>>>>>
>>>>> but I get an error on the group by. The pertinent tables sections are:
>>>>>
>>>>> table event_log
>>>>> event_time TIMESTAMP
>>>>> enduser_acnt int
>>>>>
>>>>> table enduser
>>>>> enduser_acnt int
>>>>> last_visit datetime
>>>>>
>>>>> Any help appreciated. Thanks...
>>>>> andy
>>>>>
>>>>>
>>>>
>>>> --
>>>> Andy Wallace - CISData - IDX Slave
>>>> AIM: acmwallace awallace@cisdata.net
>>>>
>>>> --
>>>> MySQL General Mailing List
>>>> For list archives: http://lists.mysql.com/mysql
>>>> To unsubscribe: http://lists.mysql.com/mysql?unsub=mgainty@hotmail.com
>>>>
>>>>
>>>

>>
>> --
>> Andy Wallace - CISData - IDX Slave
>> AIM: acmwallace awallace@cisdata.net
>>

>


--
Andy Wallace - CISData - IDX Slave
AIM: acmwallace awallace@cisdata.net
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 05-10-2008, 02:03 PM
Andy Wallace
 
Posts: n/a
Default Re: question about update/join query

Ok, I think I need to try to restate my problem.

I have an event_log table, which tracks events (!). Basic structure
is:

table: event_log
event_time timestamp
event_id int
user_id int

and my user table:

table: user
user_id int
name varchar(50)
last_visit datetime


I want to run a query that updates the last_visit column of user with
the MAX(event_time) row for which the user_id's match, but only if I
find an event:

update user U
set U.last_visit = (select max(L.event_time) from event_log L
where L.user_id = U.user_id)

I would like to do it without a subquery, I thought that the
multiple table syntax for UPDATE would do it, but I can't wrap
my head around it.

UPDATE user U, event_log L
SET U.last_visit = MAX(L.event_time)
WHERE U.user_id = L.user_id
GROUP BY L.event_time

I guess the main question is - CAN I do this? Or will I have to resort
to either a subquery, or external processing?

thanks,
andy











Martin wrote:
> Hi Andy-
>
> the MAX function needs group by for the column for which it calculating
> max value as in this example
> (select MAX(EL.event_time)
> // from event_log EL
> // where EL.enduser_acnt = E.enduser_acnt
>
> //Inner join forces selection on columns which contain non null values
> as seen here
> from event_log AS EL INNER JOIN Event AS E
> ON EL.enduser_acnt = Event.enduser_anct
>
> group by EL.event_time);
> // group by EL.enduser_acnt);
>
> HTH
> Martin
> ----- Original Message ----- From: "Andy Wallace" <awallace@cisdata.net>
> To: "Martin" <mgainty@hotmail.com>
> Cc: "mysql list" <mysql@lists.mysql.com>
> Sent: Wednesday, May 07, 2008 6:21 PM
> Subject: Re: question about update/join query
>
>
>> I want to put only the max date into the field... I was thinking that max
>> was a group function, but now that I type that out loud, perhaps I'm not
>> using all the neurons available... hmmm...
>>
>>
>> thanks,
>> andy
>>
>> Martin wrote:
>>> Hi Andy-
>>>
>>> Is there a reason why you are using Query group by clause in UPDATE
>>> statement?
>>>
>>> M
>>> ----- Original Message ----- From: "Andy Wallace" <awallace@cisdata.net>
>>> To: "mysql list" <mysql@lists.mysql.com>
>>> Sent: Wednesday, May 07, 2008 1:07 PM
>>> Subject: Re: question about update/join query
>>>
>>>
>>>> Clarification: I DON'T want to update the last_visit field if there
>>>> is no matching event record...
>>>>
>>>> I managed to get this to sort of work:
>>>>
>>>> update enduser E
>>>> set E.last_visit = (select MAX(EL.event_time)
>>>> from event_log EL
>>>> where EL.enduser_acnt = E.enduser_acnt
>>>> group by EL.enduser_acnt);
>>>>
>>>> but it updated the last_visit field to the default value if it found
>>>> no matching event_log row... which I don't want to happen.
>>>>
>>>> thanks,
>>>> andy
>>>>
>>>> Andy Wallace wrote:
>>>>> Hey all -
>>>>> I have two tables - an event_log table, and a user table. There is
>>>>> a "last_visit" column in the user table, and I want to update it from
>>>>> the event_log with the most recent event timestamp. And I want to do
>>>>> it without a subquery, eventually, both these tables will be pretty
>>>>> large, especially the event_log.
>>>>>
>>>>> I tried this:
>>>>>
>>>>> update enduser E join event_log EL on EL.enduser_acnt = E.enduser_acnt
>>>>> set E.last_visit = MAX(EL.event_time)
>>>>> group by EL.enduser_acnt
>>>>>
>>>>> but I get an error on the group by. The pertinent tables sections are:
>>>>>
>>>>> table event_log
>>>>> event_time TIMESTAMP
>>>>> enduser_acnt int
>>>>>
>>>>> table enduser
>>>>> enduser_acnt int
>>>>> last_visit datetime
>>>>>
>>>>> Any help appreciated. Thanks...
>>>>> andy
>>>>>
>>>>>
>>>>
>>>> --
>>>> Andy Wallace - CISData - IDX Slave
>>>> AIM: acmwallace awallace@cisdata.net
>>>>
>>>> --
>>>> MySQL General Mailing List
>>>> For list archives: http://lists.mysql.com/mysql
>>>> To unsubscribe: http://lists.mysql.com/mysql?unsub=mgainty@hotmail.com
>>>>
>>>>
>>>

>>
>> --
>> Andy Wallace - CISData - IDX Slave
>> AIM: acmwallace awallace@cisdata.net
>>

>


--
Andy Wallace - CISData - IDX Slave
AIM: acmwallace awallace@cisdata.net
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 05-10-2008, 02:03 PM
Neil Tompkins
 
Posts: n/a
Default RE: Order Problem

Perfect. It worked just how I wanted.

Thanks for your help.

Neil



> Date: Wed, 7 May 2008 19:54:39 +0200> To: neildtompkins@hotmail.com> Subject: Re: Order Problem> From: leannonn@gmail.com> > Hi,> > You should look at the `FIND_IN_SET` function here: > http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_find-in-set> > Your query could look like:> SELECT ProductID FROM Products WHERE Enabled= ' Yes' AND ProductID > IN(varProductID) ORDER BY FIND_IN_SET(ProductID, varProductID);> > Haven't tested it, though...> > > Take care,> Aleksandar

__________________________________________________ _______________

Discover and Win with Live Search

http://clk.atdmt.com/UKM/go/msnnkmgl...ukm/direct/01/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 03:53 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520