【问题标题】:select statements with SQL使用 SQL 选择语句
【发布时间】:2012-05-05 15:45:34
【问题描述】:

使用join语句时是否可以只对一个表使用select *?

假设这些是以下表格;

B
userID
username

A
userID
entry 
....just pretend there are more columns for the sake of this example

从表 B 中查找用户名的正确方法是什么?

select B.username, * from A
LEFT JOIN B on B.userID = A.userID
where A.entry = "XXXXX"

或者我必须列出我想要选择的所有内容,例如:

select B.username, A.userID, A.entry from A
left Join.....

【问题讨论】:

  • 当你尝试它时会发生什么?你得到的答案比在这里提问要快得多,而且你可能会在这个过程中学到一些有用的东西。 :)
  • 一定要接受这个问题的答案:)

标签: php mysql select join


【解决方案1】:

您可以使用 [表名].* 从其中一个表中选择所有字段。例如,要从表 B 中选择所有字段,请使用:

 SELECT B.*, username FROM A
 LEFT JOIN B on B.userID = A.userID
 WHERE A.entry = "XXXXX"

edit - 从 A 中选择的列用户名

【讨论】:

  • 谢谢,你的工作。我必须添加用户名,然后它才能完美运行。
【解决方案2】:

SELECT A.* FROM ... 其中A 是您要从中选择的表。

【讨论】:

    猜你喜欢
    • 2011-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-29
    • 2017-08-22
    • 1970-01-01
    相关资源
    最近更新 更多