English 中文(简体)
MySQL:伪造或空洞
原标题:MySQL: fetching a null or an empty string
  • 时间:2010-06-13 20:29:14
  •  标签:
  • mysql

我知道<代码>NUL值与空洞(<>>)值有何区别,但我想通过使用<代码>获得价值。 OR 关键词,我没有获得<代码>NUL的结果。 价值

表格一想问:

 titles_and_tags
+----+----------+------+
| id | title    | tag  |
+----+----------+------+
|  1 | title1   | NULL |
|  2 | title2   | tag1 |
|  3 | title3   | tag2 |
|  4 | edit     | NULL |
|  5 | rowdata  | div  |
+----+----------+------+

问题一如上:

select * 
  from `titles_and_tags` 
 WHERE `title` LIKE "title%" 
   AND `tag` = "tag1" OR `tag` IS NULL

因此,我想在这里看到一行(同上,第12段),BUT结果为零。 什么是错了?

http://www.ohchr.org。

职业关系,即我的主要问题是:

select * 
  from `titles_and_tags` 
WHERE `title` LIKE "title%" 
AND `tag` = "tag1" OR `tag` LIKE  % 

因此,这更像是异地、 s。

问题回答

提 出

select 
  * 
from 
  `titles_and_tags`
WHERE 
  `title` LIKE "title%" AND 
  (`tag` = "tag1" OR `tag` IS NULL)

页: 1 澄清条款,明确将逻辑合起来,确保以你打算的方式执行。

EDIT: In your edit tag like % will match all rows in which tag is not null. Any comparison other than is or not is with a null value is false. I m not sure what you re trying to do with the last query, but I suspect the one that you asked the question with originally is more like what you actually want.

根据你的评论,我的猜测是,你在数据库中插入了 NUL或空座,而不是在上。 2. 确认这项审判:

SELECT * 
FROM titles_and_tags
WHERE tag IN ( NULL ,   )

如果这种情况再次发生,那就会产生问题。

提审(逐字标注)。 或者,如果你总结使用背书而不是单一报价。 简称表

select * 
  from `titles_and_tags` 
 WHERE title LIKE "title%" 
   AND (tag = "tag1" OR tag IS NULL)




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签