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

Kueri SQL untuk mencocokkan penjual dan pembeli

Jawaban @SérgioMichels harus benar. Tapi itu tidak mendapatkan nama penjual, dan menggunakan sintaks yang (menurut saya) harus dihindari.

Jadi, inilah alternatifnya...

SELECT
  buyer.name          AS buyer,
  buyerWants.name     AS buyer_wants,      (assuming the items have names),
  buyerHas.name       AS buyer_has,
  seller.name         AS seller,
  sellerWants.name    AS seller_wants,
  sellerHas.name      AS seller_has
FROM
  People              AS buyer
INNER JOIN
  Wishlist            AS buyerWants
    ON buyerWants.person_id = buyer.person_id
INNER JOIN
  Giveaways           AS sellerHas
    ON sellerHas.item_id = buyerwish.item_id
INNER JOIN
  People              AS seller
    ON seller.person_id = sellerHas.seller_id
INNER JOIN
  WishList            AS sellerWants
    ON sellerWants.person_id = seller.person_id
INNER JOIN
  GiveAways           AS buyerHas
    ON  buyerHas.item_id = sellerWants.item_id
    AND buyerHas.person_id = buyer.person_id
WHERE
  buyer.person_id = ?


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. MySQL memberikan semua hak istimewa ke database kecuali satu tabel

  2. Temukan kolom tertentu di tabel yang tidak dikenal di database?

  3. Bantuan Kotak Centang PHP dan HTML

  4. Bagaimana saya bisa mengaktifkan log kueri lambat MySQL tanpa memulai ulang MySQL?

  5. SQL:Bagaimana cara memilih semua simpul induk di jalur Terwujud?