美文网首页
SQL之UNION ALL

SQL之UNION ALL

作者: Cute_小肥鸡 | 来源:发表于2021-09-23 20:23 被阅读0次

1、ORDER BY 排序

ORDER BY
SELECT * FROM (

  (SELECT e.FID,e.FName,e.FUpdateTime,e.FIssuedStatus,e.FBackgroundImg,u.FRealName FUserName FROM T_CC_ExerciseSet e JOIN t_um_user u ON e.FOwnedUserID = u.FID WHERE FOwnedUserID = 1 ) 

  UNION ALL 

  (SELECT e.FID,e.FName,e.FUpdateTime,e.FIssuedStatus,e.FBackgroundImg,u.FRealName FUserName FROM T_CC_ExerciseSet e JOIN T_CC_ExerciseSet_BuyList b ON e.FID = b.FExerciseSetID JOIN t_um_user u ON b.FBuyUserID = u.FID WHERE b.FBuyUserID = 1 ) 

) t ORDER BY t.FUpdateTime DESC limit 0,10

2、WHERE + LIKE 模糊查询

WHERE + LIKE
SELECT * FROM ( 
    (SELECT e.FID,e.FName,e.FOwnedUserID,e.FUpdateTime,e.FIssuedStatus,e.FBackgroundImg,e.FIntro,e.FClassificationCode,u.FRealName FROM T_CC_ExerciseSet e 
    JOIN T_UM_User u on u.FID = e.FOwnedUserID WHERE FOwnedUserID = 1 ) 
    
    UNION ALL 
    
    (SELECT e.FID,e.FName,e.FOwnedUserID,e.FUpdateTime,e.FIssuedStatus,e.FBackgroundImg,e.FIntro,e.FClassificationCode,u.FRealName FROM T_CC_ExerciseSet e 
    JOIN T_UM_User u on u.FID = e.FOwnedUserID JOIN T_CC_ExerciseSet_BuyList b ON e.FID = b.FExerciseSetID WHERE b.FBuyUserID = 1 ) 
    
) t  WHERE FClassificationCode LIKE 'TB_2_2_01%' and FName LIKE '%语文%'  ORDER BY t.FUpdateTime DESC limit 0,10

相关文章

网友评论

      本文标题:SQL之UNION ALL

      本文链接:https://www.haomeiwen.com/subject/jjgogltx.html