繁体   English   中英

MySQL查询有什么问题?

[英]What`s wrong in MySQL query?

SELECT n.nid, n.title, c.field_news_date_value, 
       c.field_news_short_text_value, c.field_news_short_text_format 
FROM node n, term_data m,  term_node p 
INNER JOIN content_type_news c 
   ON c.nid = n.nid AND c.vid = n.vid 
WHERE n.type='news' AND n.status=1 
ORDER BY c.field_news_date_value DESC.

我收到一个错误

“ on子句”中的未知列“ n.nid”。

我认为查询必须是这样的。 (假设两个表中都必须有列,名称分别为nidvid

注意:使用JOIN时在FROM子句中使用多表是不明确的

SELECT n.nid, n.title, c.field_news_date_value, 
       c.field_news_short_text_value, c.field_news_short_text_format 
FROM node n
INNER JOIN content_type_news c 
ON c.nid = n.nid AND c.vid = n.vid 
WHERE n.type='news' AND n.status=1 
ORDER BY c.field_news_date_value DESC.

尝试这个:

SELECT n.nid, n.title, c.field_news_date_value, c.field_news_short_text_value, c.field_news_short_text_format 
FROM term_data m, term_node p, node n INNER JOIN content_type_news c 
ON c.nid = n.nid AND c.vid = n.vid 
WHERE n.type='news' AND n.status=1 
ORDER BY c.field_news_date_value DESC

基本上,将node n移动到INNER JOIN运算符附近。

您需要在查询中使用AS 请使用以下查询:

SELECT 
 n.nid, n.title, 
 c.field_news_date_value, 
 c.field_news_short_text_value, 
 c.field_news_short_text_format 
FROM 
 node as n, term_data as m,  term_node as p 
INNER JOIN 
 content_type_news c ON c.nid = n.nid AND c.vid = n.vid 
WHERE 
 n.type='news' 
 AND n.status=1 
ORDER BY 
 c.field_news_date_value DESC

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM