【问题标题】:MySQL WHERE-Clause Table1.field AND Table2.field AND Table3.field equals the Same Value to avoid RedundanciesMySQL WHERE-Clause Table1.field AND Table2.field AND Table3.field 等于相同的值以避免冗余
【发布时间】:2018-11-29 15:35:48
【问题描述】:

我想知道是否可以询问具有相同字段名称的多个表并且只写一次询问的值。可能是为了避免冗余。

例如:

    SELECT * FROM table WHERE Table1.Status AND Table2.Status AND Table3.Status = 99

在结果中的每一行都应该有状态 99。

我已经对此进行了测试,但它不起作用,所以如果您有任何经验或想法,请告诉我。

我只是好奇,这是否可能。

非常感谢

【问题讨论】:

    标签: mysql where-clause redundancy


    【解决方案1】:

    您不能在同一个表中创建具有相同名称的列。

    在不同的表中你可以使用别名:

    SELECT table.status AS status1,
           table2.status AS status2,
           table3.status AS status3
    FROM table
    JOIN table2 ON table.status = table2.status
    JOIN table3 ON table.status = table3.status
    WHERE table.status = 99
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-18
      • 1970-01-01
      • 2020-12-05
      • 1970-01-01
      • 2012-04-15
      • 2022-12-19
      • 2011-01-21
      相关资源
      最近更新 更多