我有两张桌子
taxonomy_index
-nid
-tid
和
url_alias
-source
-alias
我需要查找包含url_alias.alias
来源的'taxonomy/term/' + taxonomy_index.tid
记录,而我只有taxonomy_index.nid
答案 0 :(得分:4)
SELECT url_alias.alias
FROM url_alias, taxonomy_index
WHERE url_alias.source = CONCATENATE('taxonomy/term/', taxonomy_index.tid)
AND taxonomy_index.nid = {given_nid}
答案 1 :(得分:1)
使用子查询或连接。使用子查询:
SELECT alias
FROM url_alias
WHERE source =
(SELECT CONCAT('taxonomy/term/',tid)
FROM taxonomy_index
WHERE nid = ?
)
答案 2 :(得分:1)
此查询将为您执行此操作,但可能有更有效的方法来执行此操作;)
SELECT
T.nid
,U.*
FROM
url_alias AS U
INNER JOIN (
SELECT
nid
,CONCAT('taxonomy/term/', tid) AS `alias`
FROM
taxonomy_index ) AS T
ON
U.alias = T.alias