How to write union query in doctrine?

后端 未结 2 962
星月不相逢
星月不相逢 2021-01-05 05:28

I want to use union in doctrine, i searched a lot but didn\'t get any success, this is my union query in sql, how to convert this query in doctrine?

select *         


        
2条回答
  •  花落未央
    2021-01-05 06:00

    For Union Query has some Rules

    (1) All SELECT Statements has same data type and same no of columns

    In your select query has different datatype, no of columns are not match.

    So you found Proble.

    here is solution

    select orderid, tutorialId, points, allow_multiple, question, answer1, image1, correct1, answer2, image2, correct2, answer3, image3, correct3, answer4, image4, correct4, answer5, image5, correct5,'1' as istest,'' as content,'' as media,'' as media_type_id 
    from tutorial_test 
    
    union
    
    select orderid, tutorialId,'0' as istest, content, media, media_type_id,'' as points,'' as allow_multiple,'' as question,'' as answer1,'' as image1,'' as correct1,'' as answer2,'' as image2,'' as correct2,'' as answer3,'' as image3,'' as correct3,'' as answer4,'' as image4,'' as correct4,'' as answer5,'' as image5,'' as correct5, '1' as istest,'' as content,'' as media,'' as media_type_id  
    from tutorial_elements 
    where a. tutorialId = 1 
    order by orderid asc
    

提交回复
热议问题