我目前正在尝试使用嵌套的select语句,但我的子查询正在生成NULL
值。我做错了什么?
SELECT filmid,datetime,title,description,
(
SELECT name
FROM fec_client
WHERE filmid = 'fec_film.filmid'
),
(
SELECT rating_motivation
FROM fec_rating_report
WHERE filmid = 'fec_film.filmid'
)
FROM fec_film
ORDER BY datetime DESC
答案 0 :(得分:4)
删除引号,否则你不是要比较SQL中的值而是比较字符串
SELECT filmid, datetime, title, description,
( SELECT name FROM fec_client WHERE filmid = fec_film.filmid ) AS name,
( SELECT rating_motivation FROM fec_rating_report WHERE filmid = fec_film.filmid ) AS rating
FROM fec_film ORDER BY datetime DESC
P.S。您也可以使用“AS”关键字命名这些列