Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

Bagaimana cara menulis kueri serikat pekerja dalam doktrin?

Saya sudah menemukan solusinya

Kita dapat menggunakan query ini dengan RSM sebagai berikut

"Usman pada dasarnya adalah nama tabel dan kelas"

    $rsm = new ResultSetMapping();
    $rsm->addEntityResult('Usmans', 'u');
    $rsm->addFieldResult('u', 'orderid', 'orderid');
    $rsm->addFieldResult('u', 'tutorialId', 'tutorialid');
    $rsm->addFieldResult('u', 'points', 'points');

    $query = $this->Doctrine->createNativeQuery('SELECT * FROM usman', $rsm); 
    $tutorial_tests = $query->getResult();

DAN kita dapat menggunakan tanpa ORM sebagai

$testQuery = "
    select * from (
            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  
            from tutorial_elements
        ) a 
        where a. tutorialId = $tutorial_id 
        order by orderid asc
";

$resultSets = $this->Doctrine->getConnection()->fetchAll($testQuery);


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Unggah banyak gambar dengan PHP hanya menyimpan satu jalur file ke Database MySQL

  2. LINQ ke SQL beberapa tabel kiri luar bergabung

  3. Bagaimana cara mengoptimalkan basis data kueri ini dalam basis data besar?

  4. MYSQL Deduplikat dan hapus baris duplikat dengan data paling sedikit

  5. Permintaan MySQL Pilih, SUM, LEFT JOIN