我使用关键字m
来表示来自member
的帖子,u
来自user
,
所以帖子owner id
会有类似的东西,
m-1
,m-2
,u-1
等
m-1
是member id
1
m-2
是member id
2
u-1
是user id
1
这是表格帖子,
needle_id needle_title needle_content needle_published owner_id pg_id
1 a xxx status 1 m-1 39
2 b xxx status 1 m-2 39
3 c xxx status 1 m-3 39
4 d xxx status 1 u-1 39
5 e xxx status 1 m-1 39
和表成员,
mem_id mem_screenname mem_email mem_key cat_id
1 Member one a@sample.com xxx 1
2 Member two b@sample.com xxx 1
3 Member three c@sample.com xxx 1
这是我的查询,
SELECT
n.needle_id as needleID,
n.needle_title as needleTitle,
n.needle_content as needleContent,
n.needle_published as needleApproved,
n.mem_id as needleOwnerID,
n.needle_created as needleCreated,
m.mem_screenname as needleOwnerScreenname,
m.mem_email as needleOwnerEmail,
m.mem_key as needleOwnerKey,
m.cat_name as needleOwnerType
FROM root_string_needles AS n
LEFT JOIN
(
SELECT
mm.mem_id,
mm.mem_screenname,
mm.mem_email,
mm.mem_key,
ccmm.cat_name
FROM root_members_cfm AS mm
LEFT JOIN root_category_members AS ccmm
ON ccmm.cat_id = mm.cat_id
) AS m
ON m.mem_id = n.owner_id
WHERE n.pg_id = '39'
AND m.mem_screenname IS NOT NULL
AND n.needle_published != '0'
ORDER BY n.needle_created DESC
我坚持ON m.mem_id = n.owner_id
,因为owner id
使用了前缀,但它们不匹配。
那么如何修剪owner id
列中的前缀,以便列mem id
可以匹配owner id
?
答案 0 :(得分:1)
MID(owner_id,3,2)
您还可以找到短划线( - ),然后在短划线后提取所有数据。