Wed, 06 Aug 2003 at 09:25 GMT Martin Sveegaard wrote
> On Wed, 6 Aug 2003 11:02:21 +0200, "Jimmy" <nyhedsgruppe@get2net.dk>
> wrote:
>
>>SELECT CONCAT_WS(' ', Fornavn, Efternavn) AS Navn
>>FROM test
>>WHERE LEFT(Navn, 4) = 'John'
>>
>>Jeg får fejlen: "Unknown column 'Navn' in 'where clause' "
>
> Du kan bruge HAVING:
Bruger man HAVING som WHERE kan mysqld ikke bruge index'erne.
Se her:
mysql> desc klonk;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| i | int(11) | | PRI | 0 | |
| v | varchar(20) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.03 sec)
mysql> select * from klonk;
+-----+----------+
| i | v |
+-----+----------+
| 42 | PONGPONG |
| 123 | pling |
+-----+----------+
2 rows in set (0.03 sec)
mysql> explain select * from klonk where i = 1;
+-----------------------------------------------------+
| Comment |
+-----------------------------------------------------+
| Impossible WHERE noticed after reading const tables |
+-----------------------------------------------------+
1 row in set (0.03 sec)
mysql> explain select * from klonk having i = 1;
+-------+------+---------------+------+---------+------+------+-------+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
+-------+------+---------------+------+---------+------+------+-------+
| klonk | ALL | NULL | NULL | NULL | NULL | 2 | |
+-------+------+---------------+------+---------+------+------+-------+
1 row in set (0.04 sec)
mysql> explain select * from klonk where i = 42;
+-------+-------+---------------+---------+---------+-------+------+-------+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
+-------+-------+---------------+---------+---------+-------+------+-------+
| klonk | const | PRIMARY | PRIMARY | 4 | const | 1 | |
+-------+-------+---------------+---------+---------+-------+------+-------+
1 row in set (0.03 sec)
mysql> explain select * from klonk having i = 42;
+-------+------+---------------+------+---------+------+------+-------+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
+-------+------+---------------+------+---------+------+------+-------+
| klonk | ALL | NULL | NULL | NULL | NULL | 2 | |
+-------+------+---------------+------+---------+------+------+-------+
1 row in set (0.03 sec)
/Morten