Warning: Creating default object from empty value in /www/htdocs/v030397/mysql-qotd/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php on line 4991

Warning: Creating default object from empty value in /www/htdocs/v030397/mysql-qotd/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php on line 4993

Warning: Cannot modify header information - headers already sent by (output started at /www/htdocs/v030397/mysql-qotd/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php:4991) in /www/htdocs/v030397/mysql-qotd/wp-includes/feed-rss2-comments.php on line 8
Comments on: Question 79: Which alternatives exist? http://mysql-qotd.casperia.net/archives/526 mysql 5.0/5.1 questions for learning purposes Fri, 06 Aug 2010 16:56:36 +0000 http://wordpress.org/?v=abc hourly 1 By: plogi http://mysql-qotd.casperia.net/archives/526/comment-page-1#comment-90 plogi Thu, 08 Jul 2010 17:31:08 +0000 http://mysql-qotd.casperia.net/?p=526#comment-90 <b> SQL is very powerful and there are plenty of ways to solve problems. The example below is only one possibility. It uses a join instead of the "or ... like". Instead of the subquery you could use a real table. Also there might be inventive ways of using LOCATE, REGEXP/RLIKE... <small><pre> select v1.* from mysql.help_keyword v1, (select '%TREE%' as sw union select '%TYPE%') v2 where v1.name like v2.sw; +-----------------+-------+ | help_keyword_id | name | +-----------------+-------+ | 87 | RTREE | | 107 | TYPE | | 441 | BTREE | | 445 | TYPES | +-----------------+-------+ 4 rows in set (0.03 sec) </pre></small> </b>
SQL is very powerful and there are plenty of ways to solve problems.
The example below is only one possibility. It uses a join instead of the “or … like”.
Instead of the subquery you could use a real table.
Also there might be inventive ways of using LOCATE, REGEXP/RLIKE…

select v1.* from mysql.help_keyword v1,
  (select '%TREE%' as sw union select '%TYPE%') v2
where v1.name like v2.sw;

+-----------------+-------+
| help_keyword_id | name  |
+-----------------+-------+
|              87 | RTREE |
|             107 | TYPE  |
|             441 | BTREE |
|             445 | TYPES |
+-----------------+-------+
4 rows in set (0.03 sec)


]]>