Question

I have two tables named :

url_alias
product

url_alias TABLE has following fields : id, query, keyword

id is numeric,

query is of the form "product_id=45"

keyword is of the form "product-actual-name-in-url-friendly-manner"

product table has following fields: product_id, name, language_id

What I want is to update url_alias table "keyword" field with proper url friendly string which I have generated by using mysql REPLACE function and is aliased as NEW_KEYWORD but the url friendly string needs to be auto-generated from a join of both tables .

Following query shows a SELECT query on tables properly:

SELECT u.url_alias_id, u.query, u.keyword, p.name, REPLACE( p.name, ' ', '-' ) AS NEW_KEYWORD
FROM url_alias u, product p
WHERE u.query = CONCAT( "product_id=", p.product_id )
AND p.language_id =3  

Please help me in an update query by using this query

Was it helpful?

Solution

Try it:

UPDATE url_alias u 
JOIN product p 
ON u.query = CONCAT( "product_id=", p.product_id ) 
SET u.keyword=REPLACE( p.name, ' ', '-' ) 
WHERE p.language_id =3;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top