0

我有 3 个表,我正在尝试对它们执行连接语句。

SELECT node.title, field_data_body.body_summary, 
  url_alias.alias 
FROM node, field_data_body, url_alias 
WHERE node.nid = field_data_body.entity_id 
 AND node.nid = ".node/".url_alias.source 
 AND field_data_body.bundle='article'

由于“node.nid =”.node/“.url_alias.source”,上面的行不起作用 - 这不是正确的调用方式。

我正在尝试将节点表中的 nid 列与 url_alias 表中的源列进行比较。源列的数据显示为“node/21”<- 那么当“node/”字符串挡道时我该怎么办呢?

4

2 回答 2

0

You can use REPLACE or LIKE or REGEX:

This uses REPLACE:

SELECT node.title, field_data_body.body_summary, url_alias.alias 
FROM node, field_data_body, url_alias 
WHERE node.nid = field_data_body.entity_id 
   AND node.nid = REPLACE(url_alias.source, '.node/', '')
   AND field_data_body.bundle='article'

--EDIT

Or as @datasage correctly points out, CONCAT would work too, but I think you need to use single quotes.

Good luck.

于 2013-01-30T15:28:01.413 回答
0

Seems like you want to use the CONCAT() function:

SELECT node.title, field_data_body.body_summary, 
  url_alias.alias 
FROM node, field_data_body, url_alias 
WHERE node.nid = field_data_body.entity_id 
 AND node.nid = Concat('.node/.', url_alias.source)
 AND field_data_body.bundle='article'

I would also join changing your query to use JOIN syntax:

SELECT node.title, field_data_body.body_summary, 
  url_alias.alias 
FROM node
INNER JOIN field_data_body
    on node.nid = field_data_body.entity_id 
INNER JOIN url_alias 
    ON node.nid = Concat('.node/.', url_alias.source)
WHERE field_data_body.bundle='article'
于 2013-01-30T15:28:05.203 回答