Incorrect usage of UNION and ORDER BY?

后端 未结 7 2269
感动是毒
感动是毒 2020-12-25 09:11

how can i use union and order by in mysql ?

select * from _member_facebook 
inner join _member_pts 
ON _member_facebook._fb         


        
相关标签:
7条回答
  • 2020-12-25 10:17

    Try with:

    (
      select 
        * 
      from 
         _member_facebook 
       inner join 
         _member_pts 
       ON 
         _member_facebook._fb_owner=_member_pts._username 
      where 
        _member_facebook._promote_point = 9 
      ORDER BY RAND() 
      limit 2
    ) 
    UNION ALL
    (
      select 
        * 
      from 
        _member_facebook 
       inner join 
        _member_pts 
       ON 
         _member_facebook._fb_owner=_member_pts._username 
      where 
        _member_facebook._promote_point = 8 
      limit 3
    )
    

    Although, I think you should put the ORDER BY clause at the end of the second query

    0 讨论(0)
提交回复
热议问题