Skip to content
Advertisement

Use select filed result on LEFTJOIN string

I’m trying to use id_program result from the availability table inside a string in LEFTJOIN, is it possible?

I tried using this {post.id_program} but its not working.

SELECT *
FROM availability post
    LEFT JOIN postmeta meta5 ON meta5.post_id = post.id_post 
        AND meta5.meta_key = 'items_iti_port_{post.id_program}_nights_iti_port'
WHERE post.id_post=462

EDIT: http://sqlfiddle.com/#!9/aeb4a7/3

Advertisement

Answer

I see two ways..

Using CONCAT():

meta5.meta_key = CONCAT('items_iti_port_', post.id_program, '_nights_iti_port')

With REPLACE():

meta5.meta_key = REPLACE('items_iti_port_%_nights_iti_port', '%', post.id_program)
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement