Home > Archive > PHP DB > April 2004 > RE: [PHP-DB] Request for help on (My)SQL Statement
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
RE: [PHP-DB] Request for help on (My)SQL Statement
|
|
| Nicole Swan 2004-04-27, 7:48 pm |
| Have you tried a nested query? I think your problem is that you're =
really using information from two different tables.
Maybe:
UPDATE ngc_polling SET lastrundate =3D (SELECT max(post_time) FROM =
nuke_phpbb_posts);
--Nicole
---------------------------
Nicole Swan
Web Programming Specialist
Carroll College CCIT
Helena, Montana
(406)447-4310
-----Original Message-----
From: John.Bedard@ngc.com [mailto:John.Bedard@ngc.com]
Sent: Tuesday, April 27, 2004 4:52 PM
To: php-db@lists.php.net
Subject: [PHP-DB] Request for help on (My)SQL Statement
:::Novice Alert:::
=20
I've done simple select and insert statements, so I suppose this is the =
most complicated thing I've tried to do. but seems to me it should be =
pretty easy. But I'm a designer by background, not a developer or =
programmer. I've got everything else I'm trying to do working.
=20
I'm trying to take the largest value out of one table and update another =
table. The former is a PHPBB table and the latter is a table I created =
just to store the value of the date of the most recent post for use in =
something else.=20
=20
UPDATE ngc_polling SET lastrundate =3D max(nuke_phpbb_posts.post_time)
=20
It returns "Invalid use of group function."
=20
I've been looking at the documentation on MySQL.com to no avail. I'm =
testing my query in phpMyAdmin before I try to implement it elsewhere. =
This is what I'm trying to do, any help besides "RTFM" (been doing that) =
would be greatly appreciated.
=20
Thanks!
=20
John
John Bedard | Interaction Designer (SWEIII) | Northrop Grumman Mission =
Systems | Helena, Montana, U.S.A. | john.bedard@ngc.com | 406.443.8630 | =
Fax 406.443.8601 |=20
=20
| |
| Micah Stevens 2004-04-27, 7:54 pm |
|
That would be the way to do it except that MySQL doesn't support sub-selects
until version 4.1, which is in alpha still.
-Micah
On Tuesday 27 April 2004 04:05 pm, Swan, Nicole wrote:
> Have you tried a nested query? I think your problem is that you're really
> using information from two different tables.
>
> Maybe:
>
> UPDATE ngc_polling SET lastrundate = (SELECT max(post_time) FROM
> nuke_phpbb_posts);
>
>
> --Nicole
> ---------------------------
> Nicole Swan
> Web Programming Specialist
> Carroll College CCIT
> Helena, Montana
> (406)447-4310
>
>
> -----Original Message-----
> From: John.Bedard@ngc.com [mailto:John.Bedard@ngc.com]
> Sent: Tuesday, April 27, 2004 4:52 PM
> To: php-db@lists.php.net
> Subject: [PHP-DB] Request for help on (My)SQL Statement
>
> :::Novice Alert:::
>
> I've done simple select and insert statements, so I suppose this is the
> most complicated thing I've tried to do. but seems to me it should be
> pretty easy. But I'm a designer by background, not a developer or
> programmer. I've got everything else I'm trying to do working.
>
> I'm trying to take the largest value out of one table and update another
> table. The former is a PHPBB table and the latter is a table I created just
> to store the value of the date of the most recent post for use in something
> else.
>
> UPDATE ngc_polling SET lastrundate = max(nuke_phpbb_posts.post_time)
>
> It returns "Invalid use of group function."
>
> I've been looking at the documentation on MySQL.com to no avail. I'm
> testing my query in phpMyAdmin before I try to implement it elsewhere. This
> is what I'm trying to do, any help besides "RTFM" (been doing that) would
> be greatly appreciated.
>
> Thanks!
>
> John
>
> John Bedard | Interaction Designer (SWEIII) | Northrop Grumman Mission
> Systems | Helena, Montana, U.S.A. | john.bedard@ngc.com | 406.443.8630 |
> Fax 406.443.8601 |
| |
| John Bedard 2004-04-27, 7:54 pm |
| So you're saying there's no way to do it in this version with a single =
statement?
Thanks,
John
-----Original Message-----
From: Micah Stevens [mailto:micah@raincross-tech.com]
Sent: Tuesday, April 27, 2004 5:00 PM
To: php-db@lists.php.net
Subject: Re: [PHP-DB] Request for help on (My)SQL Statement
That would be the way to do it except that MySQL doesn't support =
sub-selects=20
until version 4.1, which is in alpha still.=20
-Micah
On Tuesday 27 April 2004 04:05 pm, Swan, Nicole wrote:
> Have you tried a nested query? I think your problem is that you're =
really
> using information from two different tables.
>
> Maybe:
>
> UPDATE ngc_polling SET lastrundate =3D (SELECT max(post_time) FROM
> nuke_phpbb_posts);
>
>
> --Nicole
> ---------------------------
> Nicole Swan
> Web Programming Specialist
> Carroll College CCIT
> Helena, Montana
> (406)447-4310
>
>
> -----Original Message-----
> From: John.Bedard@ngc.com [mailto:John.Bedard@ngc.com]
> Sent: Tuesday, April 27, 2004 4:52 PM
> To: php-db@lists.php.net
> Subject: [PHP-DB] Request for help on (My)SQL Statement
>
> :::Novice Alert:::
>
> I've done simple select and insert statements, so I suppose this is =
the
> most complicated thing I've tried to do. but seems to me it should be
> pretty easy. But I'm a designer by background, not a developer or
> programmer. I've got everything else I'm trying to do working.
>
> I'm trying to take the largest value out of one table and update =
another
> table. The former is a PHPBB table and the latter is a table I created =
just
> to store the value of the date of the most recent post for use in =
something
> else.
>
> UPDATE ngc_polling SET lastrundate =3D max(nuke_phpbb_posts.post_time)
>
> It returns "Invalid use of group function."
>
> I've been looking at the documentation on MySQL.com to no avail. I'm
> testing my query in phpMyAdmin before I try to implement it elsewhere. =
This
> is what I'm trying to do, any help besides "RTFM" (been doing that) =
would
> be greatly appreciated.
>
> Thanks!
>
> John
>
> John Bedard | Interaction Designer (SWEIII) | Northrop Grumman Mission
> Systems | Helena, Montana, U.S.A. | john.bedard@ngc.com | 406.443.8630 =
|
> Fax 406.443.8601 |
--=20
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
| |
| Nicole Swan 2004-04-27, 7:54 pm |
| You're right, of course, Micah. I guess I've been using my development =
server (which has MySQL 4.1a) for so long, that I've forgotten. :)
I guess, then, that two queries would need to be used instead.
--Nicole
-----Original Message-----
From: Micah Stevens [mailto:micah@raincross-tech.com]
Sent: Tuesday, April 27, 2004 5:00 PM
To: php-db@lists.php.net
Subject: Re: [PHP-DB] Request for help on (My)SQL Statement
That would be the way to do it except that MySQL doesn't support =
sub-selects=20
until version 4.1, which is in alpha still.=20
-Micah
On Tuesday 27 April 2004 04:05 pm, Swan, Nicole wrote:
> Have you tried a nested query? I think your problem is that you're =
really
> using information from two different tables.
>
> Maybe:
>
> UPDATE ngc_polling SET lastrundate =3D (SELECT max(post_time) FROM
> nuke_phpbb_posts);
>
>
> --Nicole
> ---------------------------
> Nicole Swan
> Web Programming Specialist
> Carroll College CCIT
> Helena, Montana
> (406)447-4310
>
>
> -----Original Message-----
> From: John.Bedard@ngc.com [mailto:John.Bedard@ngc.com]
> Sent: Tuesday, April 27, 2004 4:52 PM
> To: php-db@lists.php.net
> Subject: [PHP-DB] Request for help on (My)SQL Statement
>
> :::Novice Alert:::
>
> I've done simple select and insert statements, so I suppose this is =
the
> most complicated thing I've tried to do. but seems to me it should be
> pretty easy. But I'm a designer by background, not a developer or
> programmer. I've got everything else I'm trying to do working.
>
> I'm trying to take the largest value out of one table and update =
another
> table. The former is a PHPBB table and the latter is a table I created =
just
> to store the value of the date of the most recent post for use in =
something
> else.
>
> UPDATE ngc_polling SET lastrundate =3D max(nuke_phpbb_posts.post_time)
>
> It returns "Invalid use of group function."
>
> I've been looking at the documentation on MySQL.com to no avail. I'm
> testing my query in phpMyAdmin before I try to implement it elsewhere. =
This
> is what I'm trying to do, any help besides "RTFM" (been doing that) =
would
> be greatly appreciated.
>
> Thanks!
>
> John
>
> John Bedard | Interaction Designer (SWEIII) | Northrop Grumman Mission
> Systems | Helena, Montana, U.S.A. | john.bedard@ngc.com | 406.443.8630 =
|
> Fax 406.443.8601 |
--=20
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
| |
| John Bedard 2004-04-27, 7:54 pm |
| Okay, I'll go in that direction.
Thanks!
John
-----Original Message-----
From: Swan, Nicole [mailto:NSwan@carroll.edu]
Sent: Tuesday, April 27, 2004 5:17 PM
To: php-db@lists.php.net
Subject: RE: [PHP-DB] Request for help on (My)SQL Statement
You're right, of course, Micah. I guess I've been using my development =
server (which has MySQL 4.1a) for so long, that I've forgotten. :)
I guess, then, that two queries would need to be used instead.
--Nicole
-----Original Message-----
From: Micah Stevens [mailto:micah@raincross-tech.com]
Sent: Tuesday, April 27, 2004 5:00 PM
To: php-db@lists.php.net
Subject: Re: [PHP-DB] Request for help on (My)SQL Statement
That would be the way to do it except that MySQL doesn't support =
sub-selects=20
until version 4.1, which is in alpha still.=20
-Micah
On Tuesday 27 April 2004 04:05 pm, Swan, Nicole wrote:
> Have you tried a nested query? I think your problem is that you're =
really
> using information from two different tables.
>
> Maybe:
>
> UPDATE ngc_polling SET lastrundate =3D (SELECT max(post_time) FROM
> nuke_phpbb_posts);
>
>
> --Nicole
> ---------------------------
> Nicole Swan
> Web Programming Specialist
> Carroll College CCIT
> Helena, Montana
> (406)447-4310
>
>
> -----Original Message-----
> From: John.Bedard@ngc.com [mailto:John.Bedard@ngc.com]
> Sent: Tuesday, April 27, 2004 4:52 PM
> To: php-db@lists.php.net
> Subject: [PHP-DB] Request for help on (My)SQL Statement
>
> :::Novice Alert:::
>
> I've done simple select and insert statements, so I suppose this is =
the
> most complicated thing I've tried to do. but seems to me it should be
> pretty easy. But I'm a designer by background, not a developer or
> programmer. I've got everything else I'm trying to do working.
>
> I'm trying to take the largest value out of one table and update =
another
> table. The former is a PHPBB table and the latter is a table I created =
just
> to store the value of the date of the most recent post for use in =
something
> else.
>
> UPDATE ngc_polling SET lastrundate =3D max(nuke_phpbb_posts.post_time)
>
> It returns "Invalid use of group function."
>
> I've been looking at the documentation on MySQL.com to no avail. I'm
> testing my query in phpMyAdmin before I try to implement it elsewhere. =
This
> is what I'm trying to do, any help besides "RTFM" (been doing that) =
would
> be greatly appreciated.
>
> Thanks!
>
> John
>
> John Bedard | Interaction Designer (SWEIII) | Northrop Grumman Mission
> Systems | Helena, Montana, U.S.A. | john.bedard@ngc.com | 406.443.8630 =
|
> Fax 406.443.8601 |
--=20
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--=20
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
| |
| Micah Stevens 2004-04-27, 8:56 pm |
| Not with MySQL that I know of, some local guru might have an idea..
Why are you storing the data in another table? Usually duplicating data in a
database is a big signal of flawed design. If you're using it somewhere else,
just select it from the originating table each time. Unless you're trying to
do something else that I'm not taking into account.
-Micah
On Tuesday 27 April 2004 04:14 pm, John.Bedard@ngc.com wrote:[color=darkred]
> So you're saying there's no way to do it in this version with a single
> statement?
>
> Thanks,
>
> John
>
> -----Original Message-----
> From: Micah Stevens [mailto:micah@raincross-tech.com]
> Sent: Tuesday, April 27, 2004 5:00 PM
> To: php-db@lists.php.net
> Subject: Re: [PHP-DB] Request for help on (My)SQL Statement
>
>
>
> That would be the way to do it except that MySQL doesn't support
> sub-selects until version 4.1, which is in alpha still.
>
> -Micah
>
> On Tuesday 27 April 2004 04:05 pm, Swan, Nicole wrote:
| |
| Rachel Rodriguez 2004-04-27, 8:56 pm |
|
> UPDATE ngc_polling SET lastrundate =
> max(nuke_phpbb_posts.post_time)
>
> It returns "Invalid use of group function."
>
John, you're getting that error message because the
max() function requires a GROUP BY clause.
Try this:
SELECT max(nuke_phpbb_posts.post_time)
FROM nuke_phpbb_posts
GROUP BY nuke_phpbb_posts.post_time;
=====
~Rachel
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs
http://hotjobs.sweepstakes.yahoo.com/careermakeover
| |
| John Bedard 2004-04-27, 8:56 pm |
| I'm running a notification script that does an action if the date of the =
last post is greater than the last time the script ran, which is the =
value stored in the other table. The action is to notify the members if =
there has been a new post in the past 24 hours.=20
The client is trying to generate traffic - the members aren't using the =
site. She figures if they are reminded when there's activity on the site =
(without just forwarding all posts to the members - she doesn't want to =
turn it into a mailing list per se) they'll start using it.
The design may be flawed but I don't know any other way to do it. As =
long as it serves the purpose and isn't a total abomination... :)
Thanks,
John
-----Original Message-----
From: Micah Stevens [mailto:micah@raincross-tech.com]
Sent: Tuesday, April 27, 2004 5:30 PM
To: Bedard, John
Cc: php-db@lists.php.net
Subject: Re: [PHP-DB] Request for help on (My)SQL Statement
Not with MySQL that I know of, some local guru might have an idea..=20
Why are you storing the data in another table? Usually duplicating data =
in a=20
database is a big signal of flawed design. If you're using it somewhere =
else,=20
just select it from the originating table each time. Unless you're =
trying to=20
do something else that I'm not taking into account.
-Micah
On Tuesday 27 April 2004 04:14 pm, John.Bedard@ngc.com wrote:[color=darkred]
> So you're saying there's no way to do it in this version with a single
> statement?
>
> Thanks,
>
> John
>
> -----Original Message-----
> From: Micah Stevens [mailto:micah@raincross-tech.com]
> Sent: Tuesday, April 27, 2004 5:00 PM
> To: php-db@lists.php.net
> Subject: Re: [PHP-DB] Request for help on (My)SQL Statement
>
>
>
> That would be the way to do it except that MySQL doesn't support
> sub-selects until version 4.1, which is in alpha still.
>
> -Micah
>
> On Tuesday 27 April 2004 04:05 pm, Swan, Nicole wrote:
the[color=darkred]
be[color=darkred]
another[color=darkred]
created[color=darkred]
in[color=darkred]
max(nuke_phpbb_posts.post_time)[color=darkred]
elsewhere.[color=darkred]
that)[color=darkred]
Mission[color=darkred]
406.443.8630 |[color=darkred]
| |
| Rachel Rodriguez 2004-04-27, 8:56 pm |
|
>
> John, you're getting that error message because the
> max() function requires a GROUP BY clause.
>
Ooops, my bad. It requires a GROUP BY if you are
pulling from more than one column.
=====
~Rachel
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs
http://hotjobs.sweepstakes.yahoo.com/careermakeover
| |
| Micah Stevens 2004-04-27, 10:35 pm |
|
Well then there's no reason to copy the value. Just select from the BB table.
Just:
$l = mysql_fetch_array(mysql_query("SELECT max(post_time) as latest_post FROM
nuke_phpbb_posts"));
$s = mysql_fetch_array(mysql_query("SELECT max(script_run_date) as
latest_script from script_data")
if ($l['latest_post'] > $s['latest_script']) {
echo "NEW POSTS!";
}
Or something of that nature. I've done this in the past by setting a cookie on
the user's system when they log in so I know the last time they logged in,
and then you can count how many posts have been made since they were there
last.. that works pretty good.
-Micah
On Tuesday 27 April 2004 05:02 pm, John.Bedard@ngc.com wrote:[color=darkred]
> I'm running a notification script that does an action if the date of the
> last post is greater than the last time the script ran, which is the value
> stored in the other table. The action is to notify the members if there has
> been a new post in the past 24 hours.
>
> The client is trying to generate traffic - the members aren't using the
> site. She figures if they are reminded when there's activity on the site
> (without just forwarding all posts to the members - she doesn't want to
> turn it into a mailing list per se) they'll start using it.
>
> The design may be flawed but I don't know any other way to do it. As long
> as it serves the purpose and isn't a total abomination... :)
>
> Thanks,
>
> John
>
> -----Original Message-----
> From: Micah Stevens [mailto:micah@raincross-tech.com]
> Sent: Tuesday, April 27, 2004 5:30 PM
> To: Bedard, John
> Cc: php-db@lists.php.net
> Subject: Re: [PHP-DB] Request for help on (My)SQL Statement
>
>
> Not with MySQL that I know of, some local guru might have an idea..
>
> Why are you storing the data in another table? Usually duplicating data in
> a database is a big signal of flawed design. If you're using it somewhere
> else, just select it from the originating table each time. Unless you're
> trying to do something else that I'm not taking into account.
>
> -Micah
>
> On Tuesday 27 April 2004 04:14 pm, John.Bedard@ngc.com wrote:
| |
| John Bedard 2004-04-28, 3:41 pm |
| That would work except I'd change the last line to "send email." The =
problem is the users are showing up to see any alert of new posts on the =
site. And when they do access PHPBB it will highlight those topics that =
have new posts anyway. Just got to get them there in the first place.
Thanks,
John
-----Original Message-----
From: Micah Stevens [mailto:micah@raincross-tech.com]
Sent: Tuesday, April 27, 2004 6:23 PM
To: Bedard, John
Cc: php-db@lists.php.net
Subject: Re: [PHP-DB] Request for help on (My)SQL Statement
Well then there's no reason to copy the value. Just select from the BB =
table.=20
Just:
$l =3D mysql_fetch_array(mysql_query("SELECT max(post_time) as =
latest_post FROM=20
nuke_phpbb_posts"));
$s =3D mysql_fetch_array(mysql_query("SELECT max(script_run_date) as=20
latest_script from script_data")
if ($l['latest_post'] > $s['latest_script']) {
echo "NEW POSTS!";
}
Or something of that nature. I've done this in the past by setting a =
cookie on=20
the user's system when they log in so I know the last time they logged =
in,=20
and then you can count how many posts have been made since they were =
there=20
last.. that works pretty good.=20
-Micah=20
On Tuesday 27 April 2004 05:02 pm, John.Bedard@ngc.com wrote:
> I'm running a notification script that does an action if the date of =
the
> last post is greater than the last time the script ran, which is the =
value
> stored in the other table. The action is to notify the members if =
there has
> been a new post in the past 24 hours.
>
> The client is trying to generate traffic - the members aren't using =
the
> site. She figures if they are reminded when there's activity on the =
site
> (without just forwarding all posts to the members - she doesn't want =
to
> turn it into a mailing list per se) they'll start using it.
>
> The design may be flawed but I don't know any other way to do it. As =
long
> as it serves the purpose and isn't a total abomination... :)
>
> Thanks,
>
> John
>
> -----Original Message-----
> From: Micah Stevens [mailto:micah@raincross-tech.com]
> Sent: Tuesday, April 27, 2004 5:30 PM
> To: Bedard, John
> Cc: php-db@lists.php.net
> Subject: Re: [PHP-DB] Request for help on (My)SQL Statement
>
>
> Not with MySQL that I know of, some local guru might have an idea..
>
> Why are you storing the data in another table? Usually duplicating =
data in
> a database is a big signal of flawed design. If you're using it =
somewhere
> else, just select it from the originating table each time. Unless =
you're[color=darkred]
> trying to do something else that I'm not taking into account.
>
> -Micah
>
> On Tuesday 27 April 2004 04:14 pm, John.Bedard@ngc.com wrote:
single[color=darkred]
you're[color=darkred]
is the[color=darkred]
be[color=darkred]
table I[color=darkred]
post for[color=darkred]
max(nuke_phpbb_posts.post_time)[color=darkred]
I'm[color=darkred]
elsewhere.[color=darkred]
Mission[color=darkred]
406.443.8630[color=darkred]
--=20
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
|
|
|
|
|