1

I have two tables

taxonomy_index
-nid
-tid

and

url_alias
-source 
-alias

I need to find url_alias.alias record which have source 'taxonomy/term/' + taxonomy_index.tid and I have only taxonomy_index.nid

3 Answers 3

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}
Sign up to request clarification or add additional context in comments.

Comments

1

Either use a subquery or a join. With a subquery:

SELECT alias
FROM url_alias 
WHERE source = 
 (SELECT CONCAT('taxonomy/term/',tid)
  FROM taxonomy_index
  WHERE nid = ?
 )

1 Comment

Just be aware that subqueries alone are very slow, and especially when you are using CONCAT. Just a heads up
1

This query will do that for you although there may be more efficient way to do this ;)

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.