开发者

Select all but on element in JOIN MySQL

I have the code here to join two tables. However I don't want to get the password element from the Accounts database. How could I do this?

"SELECT f.*, a.* 
   FROM Following as f 
   JOIN Accounts as a on f.followingUserID = a.id开发者_如何转开发 
  WHERE `followingUserID` = '$acID'


There is no SQL convention for "all columns EXCEPT FOR ..." -- it's either all, or you define the list by hand:

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'


Name the columns instead of retrieving them all.

Instead of a.*, :

a.ColumnName1, a.ColumnName2, etc....


If you don't want to select a password element you will need to change the a.* to select each column individually i.e.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜