【问题标题】:get data from 3 different tables in mysql using c#使用c#从mysql中的3个不同表中获取数据
【发布时间】:2015-12-23 01:20:00
【问题描述】:

我在mysql中有3个表

theatredet(theatid,theatname,locid)
location(locid,locname)
screendet(scname,theatid,seats avail)
  1. 我想从 theatredet 获得完整的餐桌价值,
  2. 需要根据locid从第二张表中获取locname
  3. 需要从 theatid 的第三个表基础中获取可用席位、scname

如何使用 c# 进行单个查询

【问题讨论】:

  • 您能否向我们提供您尝试过的代码以及您已经拥有的代码?如果没有任何代码,我们将无法为您提供适当的帮助。
  • @Roman:iam 还没试过?我需要代码..
  • 好吧,请注意,StackOverflow 不是要求您没有的代码的地方。如果您有任何疑问或问题取决于您的代码,请寻求帮助。
  • 代码?抱歉,他们是绝密,以防止未经授权的导弹发射

标签: c# mysql


【解决方案1】:

这可能对你有帮助

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 替换为您想要用作条件的数字。

【讨论】:

    【解决方案2】:

    尝试 SQl 内连接。

    从 theatredet 内部连接位置选择 theatredet.*,location.locname,screendet.scname,screendet.seats 效用 theatredet.locid=location.locid 内部连接 ​​screendet on screendet.theatid=theatredet.theatid

    【讨论】:

      【解决方案3】:

      这是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 Connector 以下是在 C# 中使用连接器的方法:CodeProject

      【讨论】:

        猜你喜欢
        • 2021-12-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-07
        • 2021-11-11
        • 2019-01-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多