表结构如下:
mysql> desc article;
+--------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| pid | int(11) | YES | | NULL | |
| rootid | int(11) | YES | | NULL | |
| title | varchar(255) | YES | | NULL | |
| cont | text | YES | | NULL | |
| pdate | datetime | YES | | NULL | |
| isleaf | int(11) | YES | | NULL | |
+--------+--------------+------+-----+---------+----------------+ 如何找出title或者cont中带有“大象”且pid为0的记录?我以为用下面的语句就能搞定了:select * from article where title like '%大象%' or cont like '%大象%' and pid = 0;可惜……
那只是我以为!
感觉好像可以先找出pid=0的记录,然后再从中找出title或者cont中带有“大象”的记录,可就是不知道怎么下手啊,希望大家帮帮忙,在此提前表示感谢!
mysql> desc article;
+--------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| pid | int(11) | YES | | NULL | |
| rootid | int(11) | YES | | NULL | |
| title | varchar(255) | YES | | NULL | |
| cont | text | YES | | NULL | |
| pdate | datetime | YES | | NULL | |
| isleaf | int(11) | YES | | NULL | |
+--------+--------------+------+-----+---------+----------------+ 如何找出title或者cont中带有“大象”且pid为0的记录?我以为用下面的语句就能搞定了:select * from article where title like '%大象%' or cont like '%大象%' and pid = 0;可惜……
那只是我以为!
感觉好像可以先找出pid=0的记录,然后再从中找出title或者cont中带有“大象”的记录,可就是不知道怎么下手啊,希望大家帮帮忙,在此提前表示感谢!
解决方案 »
- 急求帮助,谁有mysql-5.1.8的源代码?
- 求 mysql 的学习方法
- mysql:为什么要分开过程和函数
- 请问怎么实现自动把MYSQL表的数据IMPORT成TXT格式呢?
- mysql配置JDO的问题
- mysql的触发器大家都在什么情况下使用
- SQuirreL SQL Client操作Mysql是的中文乱码问题
- EMS SQL MANAGER录入数据的问题
- 一个字符集编码问题
- 为什么 MySql 的路灯老是红灯?并且,如果要启动时,没有任何反应?
- [菜鸟]mysql 建立带外键的表的问题
- 误操作造成root用户没了,如何办呀,我update user set user=password('123456') where user='root'
where (title like '%大象%' or cont like '%大象%') and pid = 0;
这样试一下
实在记不住,可以用括弧括住,就像楼上的几位说的那样