【问题标题】:select all from table1 and just one column from table2从 table1 中选择所有,从 table2 中选择一列
【发布时间】:2018-01-26 23:16:45
【问题描述】:

我有这个问题:

select *, U.TYPE from table1
LEFT JOIN table2 AS U ON (U.ID=ID)

它的作用是为我提供 table1 和 table2 中的所有列。除了在 select 语句中列出 table1 中的所有字段而不是放置 * 之外,是否有一种更简洁的方法可以从 table1 中获取所有列和 table2 中的一列?

【问题讨论】:

  • select TABLE1.*, U.TYPE from table1 LEFT JOIN table2 AS U ON (U.ID=ID)
  • 你在开玩笑吧!?!?!?!有那么简单吗!?!?!我觉得自己像个白痴!谢谢你!我自己怎么没想到。感觉很愚蠢;/继续将其作为答案发布,我将把它作为答案并向上发布。
  • @GordonLinoff 不,确实如此,op 使用的是SELECT *, u.type,所以它首先返回两个表中的每一列
  • 别担心@MikePala,我们每个人都曾在某个时候经历过一个或多个这样的时刻 :)

标签: sql


【解决方案1】:

你可以这样做

select a.*, b.TYPE from table1 a
LEFT JOIN table2 b ON (a.ID=b.ID)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-10
    • 1970-01-01
    相关资源
    最近更新 更多