==============小白问题:SQL 优化=============
在看一本oracle database 11g sql的书。
知道你们有疑问了,为什么oracle的问题跑这来问?
我先回答,我觉得这个版块更活跃一些,高手更多一些,所以跑这来问了,原理应该是差不多的。
我看到书中其中一条建议
Use Table Joins Rather than Multiple Queries
即用表连接,而不用多条查询语句。
小白问题:我想当然是table joins就是要有join关键字的,但是是例子中给出的是没join关键字的。
(1)是不是没有join关键字,但是有下面例子中那样的where语句的也叫join?
-- GOOD (one query with a join)
SELECT p.name, pt.name
FROM products p, product_types pt
WHERE p.product_type_id = pt.product_type_id
AND p.product_id = 1;
--You should choose the join order in your query so that
--you join fewer rows to tables later in
--the join order. For example, say you were joining three
--related tables named tab1, tab2, and
--tab3. Assume tab1 contains 1,000 rows, tab2 100 rows,
--and tab3 10 rows. You --should join
--tab1 with tab2 first, followed by tab2 and tab3.
SELECT a.name, b.name, c.name
FROM tab1 a, tab2 b, tab3 c,
WHERE a.id = b.id AND b.id = c.id
AND a.id = 1;
(2)我的理解是这样写:
SELECT a.name, b.name, c.name
FROM tab1 a inner join tab2 b on a.id = b.id
inner join tab3 c on b.id = c.id
WHERE a.id = 1;