[英]MySQL Query and select data from two tables
我有兩張桌子
taxonomy_index
-nid
-tid
和
url_alias
-source
-alias
我需要找到具有來源'taxonomy/term/' + taxonomy_index.tid
url_alias.alias
記錄,而我只有taxonomy_index.nid
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}
使用子查詢或聯接。 帶有子查詢:
SELECT alias
FROM url_alias
WHERE source =
(SELECT CONCAT('taxonomy/term/',tid)
FROM taxonomy_index
WHERE nid = ?
)
該查詢將為您完成此操作,盡管可能有更有效的方法;)
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.