RE: [PHP-DB] newbie: how to return one iteration *per unique date (DAY!)* in a timestamp column?
> -Original Message- > From: Govinda [mailto:govinda.webdnat...@gmail.com] > Sent: 05 August 2009 01:41 > > > Taking this: > > SELECT count(*) AS > > `CountUniqueDatesInMyTbl`, date(solarAWDateTime) AS `uniqueDate`, > > 'aweber_7solar_aw' AS `tableAlias` FROM aweber_7solar_aw GROUP BY > > DATE(solarAWDateTime) Just one other tiny point of style here: having given the expression date(solarAWDateTime) the alias uniqueDate, you should probably use that alias to refer to the same thing elsewhere in your query, such as in the GROUP BY column. So: SELECT count(*) AS `CountUniqueDatesInMyTbl`, date(solarAWDateTime) AS `uniqueDate`, 'aweber_7solar_aw' AS `tableAlias` FROM aweber_7solar_aw GROUP BY `uniqueDate`; That's how I'd write it, anyway. Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Leeds Metropolitan University, C507, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] newbie: how to return one iteration *per unique date (DAY!)* in a timestamp column?
Just one other tiny point of style here: having given the expression date(solarAWDateTime) the alias uniqueDate, you should probably use that alias to refer to the same thing elsewhere in your query, such as in the GROUP BY column. So: ... That's how I'd write it, anyway. I like to know your thinking; I'm working to learn to 'think in MySQL'.. so every input is appreciated. thanks! -G -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] newbie: how to return one iteration *per unique date (DAY!)* in a timestamp column?
Me/this again. this works good: $query = "SELECT COUNT(*) AS `CountUniqueDatesInMyTbl`, date(solarLandingDateTime) AS `uniqueDate`, 't7solar_landing' AS `tableAlias` FROM t7solar_landing GROUP BY uniqueDate ORDER BY uniqueDate DESC LIMIT 62 UNION ALL SELECT count(*) AS `CountUniqueDatesInMyTbl`, date(solarAweberConfDateTime) AS `uniqueDate`, 'aweber_7solar_confirm' AS `tableAlias` FROM aweber_7solar_confirm GROUP BY uniqueDate ORDER BY uniqueDate DESC LIMIT 62 UNION ALL SELECT count(*) AS `CountUniqueDatesInMyTbl`, date(solarAWDateTime) AS `uniqueDate`, 'aweber_7solar_aw' AS `tableAlias` FROM aweber_7solar_aw GROUP BY uniqueDate ORDER BY uniqueDate DESC LIMIT 62"; except that I just added the ORDER BY clause onto each SELECT segment, and now I get this error: query failed: Incorrect usage of UNION and ORDER BY How can I order the results while still doing the UNION ALLs? -Govinda -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] newbie: how to return one iteration *per unique date (DAY!)* in a timestamp column?
> except that I just added the ORDER BY clause onto each SELECT segment, > and now I get this error: > query failed: Incorrect usage of UNION and ORDER BY > > How can I order the results while still doing the UNION ALLs? You should only need one ORDER BY clause at the end of the whole query: (SELECT...) UNION ALL (SELECT...) UNION ALL (SELECT...) ORDER BY... I'm not sure if this syntax is portable to other SQL-based DBMSes, though. I'm certain that one system we use at work doesn't support it, but it's kind of a dinosaur so I don't like to draw too many conclusions from what it doesn't support. Ben -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] newbie: how to return one iteration *per unique date (DAY!)* in a timestamp column?
Ford, Mike wrote: -Original Message- From: Govinda [mailto:govinda.webdnat...@gmail.com] Sent: 05 August 2009 01:41 Taking this: SELECT count(*) AS `CountUniqueDatesInMyTbl`, date(solarAWDateTime) AS `uniqueDate`, 'aweber_7solar_aw' AS `tableAlias` FROM aweber_7solar_aw GROUP BY DATE(solarAWDateTime) Just one other tiny point of style here: having given the expression date(solarAWDateTime) the alias uniqueDate, you should probably use that alias to refer to the same thing elsewhere in your query, such as in the GROUP BY column. So: SELECT count(*) AS `CountUniqueDatesInMyTbl`, date(solarAWDateTime) AS `uniqueDate`, 'aweber_7solar_aw' AS `tableAlias` FROM aweber_7solar_aw GROUP BY `uniqueDate`; That's a mysqlism :( It's not portable to other db's (apparently it's not part of the sql-spec). -- Postgresql & php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] newbie: how to return one iteration *per unique date(DAY!)* in a timestamp column?
>> Just one other tiny point of style here: having given the expression >> date(solarAWDateTime) the alias uniqueDate, you should probably use >> that alias to refer to the same thing elsewhere in your query, such as >> in the GROUP BY column. So: [8<] > That's a mysqlism :( It's not portable to other db's (apparently it's > not part of the sql-spec). I think I've even seen MySQL reject it in some cases. Ben -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php