0
我在數據庫中有20個表。MySQL從多個表中獲取結果
我所試圖做的就是誰擁有得分所有學生的名單高於70
我的查詢:
SELECT mysql.*, mssql.*, orecle.* FROM mysql, mssql, orecle;
+----------+------------+------------+------------+----------+------------+------------+------------+----------+-------------+-------------+-------------+
| student | mysqltest1 | mysqltest2 | mysqltest3 | student | mssqltest1 | mssqltest2 | mssqltest3 | student | orecletest1 | orecletest2 | orecletest3 |
+----------+------------+------------+------------+----------+------------+------------+------------+----------+-------------+-------------+-------------+
| student1 | 60 | 70 | 80 | student1 | 80 | 60 | 70 | student1 | 80 | 60 | 50 |
| student2 | 50 | 80 | 90 | student1 | 80 | 60 | 70 | student1 | 80 | 60 | 50 |
| student1 | 60 | 70 | 80 | student2 | 90 | 70 | 50 | student1 | 80 | 60 | 50 |
| student2 | 50 | 80 | 90 | student2 | 90 | 70 | 50 | student1 | 80 | 60 | 50 |
| student1 | 60 | 70 | 80 | student1 | 80 | 60 | 70 | student2 | 90 | 70 | 80 |
| student2 | 50 | 80 | 90 | student1 | 80 | 60 | 70 | student2 | 90 | 70 | 80 |
| student1 | 60 | 70 | 80 | student2 | 90 | 70 | 50 | student2 | 90 | 70 | 80 |
| student2 | 50 | 80 | 90 | student2 | 90 | 70 | 50 | student2 | 90 | 70 | 80 |
+----------+------------+------------+------------+----------+------------+------------+------------+----------+-------------+-------------+-------------+
8 rows in set (0.00 sec)
爲什麼它顯示8行,而不是2?
我希望發生的是當查詢運行,只輸出有一個值高於70
我厭倦了一對夫婦查詢但是似乎沒有任何工作,他們都給了我錯誤的細胞。
SELECT mysql.*, mssql.*, orecle.* FROM mysql, mssql, orecle where ALL > 70;
SELECT mysql.*, mssql.*, orecle.* FROM mysql, mssql, orecle where ALL > '70';
SELECT mysql.*, mssql.*, orecle.* FROM mysql, mssql, orecle where mysql.* OR mssql.* OR orecle.* > 70;
SELECT mysql.*, mssql.*, orecle.* FROM mysql, mssql, orecle where mysql.* OR mssql.* OR orecle.* > '70';
該查詢會給我一個行,我認爲是更好的
SELECT mysql.*, mssql.*, orecle.* FROM mysql, mssql, orecle where mysql.student='student1' AND mssql.student='student1' AND orecle.student='student1';
+----------+------------+------------+------------+----------+------------+------------+------------+----------+-------------+-------------+-------------+
| student | mysqltest1 | mysqltest2 | mysqltest3 | student | mssqltest1 | mssqltest2 | mssqltest3 | student | orecletest1 | orecletest2 | orecletest3 |
+----------+------------+------------+------------+----------+------------+------------+------------+----------+-------------+-------------+-------------+
| student1 | 60 | 70 | 80 | student1 | 80 | 60 | 70 | student1 | 80 | 60 | 50 |
+----------+------------+------------+------------+----------+------------+------------+------------+----------+-------------+-------------+-------------+
1 row in set (0.01 sec)
然而,可以讓複雜的〜20桌; 此外,我只想看到值70或更高的結果。
這會發生什麼最好的查詢?
聯盟聲明? – fyr 2014-10-20 21:05:25
'JOIN's和'INDEX'es – doublesharp 2014-10-20 21:06:53