正如我在评论中所说,这很容易(如果您阅读手册):
SELECT field1, field2, field3 AS altName, lastFieldNoCommaHere
FROM table
WHERE someField = 'value'
AND id IN (1,2,3,4,5,6,7,8,9)
AND (dateField > NOW()
OR dateField IS NULL);
RTM 并且不使用mysql_*
扩展,它已被弃用。使用PDO
or mysqli_*
,不仅仅是因为弃用问题,而是出于各种原因。
当您在 where 子句中使用时movie.star1
,您也应该查看语法:JOIN
SELECT actor_id.name
FROM actor_id
LEFT JOIN movie
ON movie.star1 = actor_id.actor_id
WHERE actor_id.actor_id IN (1,2,4,5,6,7,8,123);
那可能就是您所追求的,或者可能是:
SELECT actor_id.name
FROM actor_id
WHERE actor_id.actor_id
IN ( SELECT movie.star1
FROM movie
WHERE movie.release_date >= '2012-01-01');
这是子查询的示例。小心这一点,因为它通常很慢......
正如 Fluffeh 向我指出的那样,你不能选择多个值,而不得不求助于这样的东西:
SELECT actor_id.name
FROM actor_id
WHERE actor_id.actor_id
IN ( SELECT IFNULL(movie.star1, IFNULL(movie.star2, movie.star3))
FROM movie
WHERE movie.release_date >= '2012-01-01');
或者:
SELECT actor_id.name
FROM actor_id
WHERE actor_id.actor_id
IN ( SELECT IF (movie.star1 <= 12,
IF (movie.star2 <= 15,
movie.star3,
movie.star2),
movie.star1)
FROM movie
WHERE movie.release_date >= '2012-01-01');