sql >> Database >  >> RDS >> Mysql

Waarom gebruikt MySQL niet de primaire sleutel op JOIN plus ORDER?

Kun je deze versie proberen (het krijgt in feite eerst de 420 rijen van de corder tabel, houdt de 20 ervan en doet dan de 3 buitenste joins):

SELECT
    corder.id,
    corder.public_id,
    CONCAT(buyer.fname," ",buyer.lname) AS buyer_name,
    corder.status,
    corder.payment,
    corder.reserved AS R,
    corder.tracking_id != "" AS A,
    corder.payment_received AS pay_date,
    invoice.invoice_no AS inv,
    invoice.receipt_no AS rec,
    invoice.public AS pub_inv,
    proforma.proforma_no AS prof,
    proforma.public AS pub_pf,
    corder.rating,
    corder.rating_comments!="" AS got_comment
FROM
    ( SELECT * 
      FROM corder
      ORDER BY
        id DESC 
      LIMIT 400, 20
    )
    AS corder
LEFT JOIN user as buyer ON buyer.id = corder.buyer
LEFT JOIN invoice AS invoice ON invoice.id = corder.invoice
LEFT JOIN invoice AS proforma ON proforma.id = corder.proforma
ORDER BY
    corder.id DESC ;



  1. Toon waarden uit een MySQL-databasetabel in een HTML-tabel op een webpagina

  2. Hoe verklein ik mijn SQL Server-database?

  3. Hoe regexp in sqlite te gebruiken

  4. Hoe stel je een AUTO_INCREMENT-veld in om te beginnen met de waarde 6000 in mysql?