youv youv - 9 months ago 47
MySQL Question

Select query for particular column value

I have two tables like the following. How can I query this to join these two tables? I need to implement this in one query.


Id name mark
--- ---- ----
1 name1 40
2 name2 30
3 name3 20
4 name4 80


details_id address userid
---------- ------- ---
1 A1 user=2
2 dd user=3
3 gg user=1
4 kk user=4

I need to join these tables using id and userid in both tables.

select * from table1 left join table2 on = table2.userid


Try something like this:

FROM table1 
    LEFT JOIN table2 
        ON 'user=' + CAST( AS char(10)) = table2.userid

Alternatively, you could use a substring or something similar to remove the 'user=' and cast it as an integer for the join.