2013-03-07 59 views
2

上一個新的MysqlMySQL _在單個查詢中檢索多個行和列

我想從數據庫中檢索包含StrainName = M18的所有列,但出現錯誤。請在此幫助我

SELECT * 

strain.strainName, 
feature.contigId, 
feature.startPosition, 
feature.stopPosition, 
feature.orfId, 
feature.orfType, 
feature.funcClassification, 
feature.rastId, 
feature.strand 
from feature,strain 
where feature.id=strain.id and strainName='M18'; 

錯誤1064(42000):您的SQL語法錯誤;檢查對應於你的MySQL服務器版本使用附近的「strain.strainName,feature.contigId,feature.startPosition,feature.stopPosition,FE」在行1

+0

在'*'後加''''。 – 2013-04-23 19:16:38

回答

1

你需要*

後添加逗號正確的語法手冊
SELECT *,      -- <<====== HERE 
     strain.strainName, 
     feature.contigId, 
     feature.startPosition, 
     feature.stopPosition, 
     feature.orfId, 
     feature.orfType, 
     feature.funcClassification, 
     feature.rastId, 
     feature.strand 
from feature,strain 
where feature.id=strain.id and 
     strainName='M18'; 
+0

這是什麼意思?選擇所有列並再次重複這些列?我以前從未見過與列名使用的明星。謝謝 – 2013-03-07 01:26:05

+0

那是有效的語法嗎? – Scotch 2013-03-07 01:29:21

+0

@Saher此答案僅說明錯誤的位置。也許OP想嘗試一些東西。即使用戶使用'*'並選擇列,那麼重複的列將不會顯示在列表中。 – 2013-03-07 01:31:50

1

來獲取所有列:

SELECT * from feature,strain 
where feature.id=strain.id and strainName='M18'; 

得到具體列:

SELECT      
     strain.strainName, 
     feature.contigId, 
     feature.startPosition, 
     feature.stopPosition, 
     feature.orfId, 
     feature.orfType, 
     feature.funcClassification, 
     feature.rastId, 
     feature.strand 
from feature,strain 
where feature.id=strain.id and 
     strainName='M18';