2014-08-31 65 views
0

在MySQL查詢與多個表中的「計數」,我有以下MySQL查詢:添加「來自」條款

select * from u, s, c, ut, m 

工作正常,顯示所有表的列。我只想將記錄計數添加到u表中。

我嘗試這樣做:

select (select count(*) as totalcount from u), * from u, s, c, ut, m 

但它拋出一個錯誤。

+0

如果發生錯誤,則發佈錯誤消息。 – ydaetskcoR 2014-08-31 08:24:51

+0

你應該問一個真實世界的例子你的問題。 – GhostGambler 2014-08-31 08:28:29

回答

1

此查詢工作對我來說:

select * , (select count(*) from u) as totalcount from u , s , c , ut , m ; 
0

SELECT t1.*, (SELECT COUNT(*) FROM table t3) AS TotalCount FROM table_Name1 t1, tableName t;

這可能會幫助你。 指定要從中檢索哪個表的列。如果你想要所有列更好的方法是join表。

0
select (select count(*) as totalcount from u), * from u, s, c, ut, m 

我試試你的查詢,並能正常工作。試試這個。我希望它能起作用。

select (select count(*) from u) as totalcount, * from u, s, c, ut, m