当前位置: 动力学知识库 > 问答 > 编程问答 >

php - 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'
分享给朋友:
您可能感兴趣的文章:
随机阅读: