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.
Table1
Id name mark
--- ---- ----
1 name1 40
2 name2 30
3 name3 20
4 name4 80
Table2
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 table1.id = table2.userid
Try something like this:
SELECT*
FROM table1
LEFT JOIN table2
ON 'user=' + CAST(table1.id 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.