OT : help needed with a mySQL request

Peter Haworth pete at lcsql.com
Fri Nov 22 14:21:53 EST 2013


On Fri, Nov 22, 2013 at 9:40 AM, John Craig <john at splash21.com> wrote:

> mysql> SELECT * FROM data HAVING (SELECT COUNT(id) FROM data AS data2
> WHERE name = data.name AND year < 2013) = 0;
> +----+--------+------+
> | id | name   | year |
> +----+--------+------+
> |  8 | Katy   | 2013 |
> |  9 | Tracey | 2013 |
> +----+--------+------+
>

Hi John,
Don't think that will work if there are rows with years greater than the
one he's looking for, for example:

Katy 2010
Katy 2011
Tracey 2010
Tracey 2012

You'd still get Tracy and Katy selected.

I'm learning something about mySQL though.  In SQLite, HAVING is a
subclause of GROUP but looks like it can stand on its own in mySQL.

Pete
lcSQL Software <http://www.lcsql.com>



More information about the use-livecode mailing list