As I said in my comment, it's quite easy (if you read the manual):
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 and don't use mysql_*
extension, it's deprecated. Use PDO
or mysqli_*
, not just because of the deprecation issue, But for various reasons.
Seing as you're using movie.star1
in your where clause, you should look into the JOIN
syntax, too:
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);
That's, probably, what you're after, or perhaps:
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');
This is an example of a sub-query. Be careful with this, because it's often quite slow...
And as Fluffeh pointed out to me, you can't select multiple values, and have to resort to something like this:
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');
Or:
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');