sql - Join two tables by column -


so have 2 table, comment_table , post_table,

comment_table:

link_id   body t3_100    people on stackoverflow smart  t3_100    stackoverflow place raise questions t3_101    can learn sql  t3_102    happy eastern t3_102    did bunny go? 

post_table

id      title 100     thought on stackoverflow 101     sql beginner 102     eastern  105     title has no comments  

"link_id" concatenated 't3_' + id post_table. want 2 join 2 tables "id".

expected output

id      title                        link_id   body 100     thought on stackoverflow     t3_100    people on stackoverflow smart 100     thought on stackoverflow     t3_100    stackoverflow place raise questions 101     sql beginner                 t3_101    can learn sql  102     eastern                      t3_102    happy eastern 102     eastern                      t3_102    did bunny go? 105     title has no comments   t3_105    null 

here script have,

select pt.id, pt.title, ct.link_id, ct.body   post_table pt  left outer join comment_table ct on pt.id = ct.concat('t3_', link_id) 

it has syntax error, how think can fix expected output?

you assigning alias function, should field.

this work.

select pt.id, pt.title, ct.link_id, ct.body   post_table pt  left outer join comment_table ct on ct.link_id = concat('t3_', pt.id) 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -