2011-09-24 3 views
0

의 출력이유는 출력 데이터가 대응하지 여기 연합 열의 모든 쿼리

어레이 (7) {[ "타입"] => 문자열 (16) "새로운 포스트 코멘트"[ "book_id 조각의 "" "test"[ "content"] => 문자열 (19) "" "" "2011-07-16 03:20:01"[ "create_time"] => 문자열 (1) "3"[ "id"] => 문자열 (1) "1"}

그리고이 부분은 내 검색어

     SELECT 'bookcomment' AS type 
           ,b.book_id 
           ,b.name 
           ,c.book_id 
           ,c.author_id 
           ,c.content 
           ,c.create_time AS create_time 
           ,u.id 
           ,u.name 
           FROM tbl_book AS b, 
              tbl_book_comment AS c, 
              tbl_user AS u 
           WHERE u.id=c.author_id in (1,2) AND b.book_id=c.book_id 


        UNION ALL 

        SELECT 'new post comment' AS type 
          ,po.post_id 
          ,po.title 
          ,pc.author_id 
          ,pc.content 
          ,pc.create_time AS create_time 
          ,pc.post_id 
          ,u.id 
          ,u.name 
          FROM tbl_post as po, 
             tbl_post_comment as pc, 
             tbl_user as u 
          WHERE u.id=pc.author_id in(1,2) AND po.post_id=pc.post_id 


        UNION ALL 

        SELECT 'bookrating' AS type 
           ,b.book_id as one 
           ,b.name 
           ,ra.book_id 
           ,ra.user_id 
           ,ra.rating 
           ,ra.create_time AS create_time 
           ,u.id 
           ,u.name 
           FROM tbl_book AS b, 
              tbl_user_book_rating AS ra, 
              tbl_user AS u 
           WHERE u.id=ra.user_id in (1,2) AND b.book_id=ra.book_id 


        UNION ALL... 
ORDER BY create_time DESC 

결과에 따르면 'author_id'에 해당하는 데이터가 있어야합니다. 'content'와 'content'는 'create_time'이어야합니다. 내 검색어에 무슨 문제가 있습니까?

답변

1

두 번째 SELECT에서 열의 순서가 뒤섞인 것처럼 보입니다. 귀하의 열 (오른쪽에서 세 번째, 두 번째 중앙에, 왼쪽에있는 첫 번째 쿼리)이 같다 :

type   type   type 
b.book_id  po.post_id  one 
b.name   po.title  b.name 
c.book_id  pc.author_id ra.book_id 
c.author_id  pc.content  ra.user_id 
c.content  create_time  ra.rating 
create_time  pc.post_id  create_time 
u.id   u.id   u.id 
u.name   u.name   u.name 

순서는 그것의 모양에 의해 pc.author_id에 혼합됩니다.