在JOIN MySQL中选择all on but元素

时间:2011-06-09 00:34:15

标签: php mysql sql

我这里有代码加入两个表。但是,我不想从Accounts数据库中获取密码元素。我怎么能这样做?

"SELECT f.*, a.* 
   FROM Following as f 
   JOIN Accounts as a on f.followingUserID = a.id 
  WHERE `followingUserID` = '$acID'

3 个答案:

答案 0 :(得分:1)

“所有列除外...”没有SQL约定 - 它可以是全部,也可以手动定义列表:

SELECT f.*, 
       a.col1, a.col2,
       a.`col name using spaces not good`
  FROM FOLLOWING as f 
  JOIN ACCOUNTS as a on f.followingUserID = a.id 
 WHERE f.followingUserID = '$acID'

答案 1 :(得分:0)

为列命名,而不是全部检索它们。

而不是。*,:

a.ColumnName1,a.ColumnName2等......

答案 2 :(得分:0)

如果您不想选择密码元素,则需要更改a.*以单独选择每个列,例如

SELECT f.*, a.account_id, a.name 
FROM following as f 
JOIN accounts as a on f.followingUserId = a.id 
WHERE followingUserID = '$acID'