簡體   English   中英

使用c#從mysql中的3個不同表中獲取數據

[英]get data from 3 different tables in mysql using c#

我在 mysql 中有 3 個表

theatredet(theatid,theatname,locid)
location(locid,locname)
screendet(scname,theatid,seats avail)
  1. 我想從 theatreet 獲得完整的表價值,
  2. 需要根據locid從第二個表中獲取locname
  3. 需要獲得席位,scname 來自 theatid 的第三個表基礎

我怎么可能在單個查詢中使用 c#

這可能會幫助你

Select td.*, l.locname, sd.seats_avail, sd.scname 
From theatredet td, location l, screendet sd
WHERE l.locid = 1 AND sd.theatid = 1

您可以將 1 替換為您想要用作條件的號碼。

嘗試 SQL 內連接。

選擇 theatredet.*,location.locname,screendet.scname,screendet.seats 從 theatredet 內連接位置可用 theatredet.locid=location.locid 內連接 screendet on screendet.theatid=theatredet.theatid

這是sql語句:

Select theatredet.*, locname, avail, scname
From theatredet 
Inner Join location ON location.locid = theatredet.locid
Inner Join screendet ON screendet.theatid = theatredet.theatid;

但是您需要將 MySql 連接器綁定到您的項目。 看看這個: MySql 連接器這里是你如何在 C# 中使用連接器: CodeProject

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM