cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

First Query

7,568

After starting the database when the first query takes longer to run. For example, a simple query to get the date of the last sale, after this consultation the other run faster:

select max(date_sale) as data_sale from tbsales, tbsales_tribute
where tbsales.emp = tbsales_tribute.emp
and tbsales.sale = tbsales_tribute.sale
and tbsales.emp = 1
and tbsales_tribute.type = 5

or

select max(date_sale) as data_sale
from tbsales
key join tbsales_tribute
where tbsales.emp = 1 
and tbsales_tribute.type = 5

or

select max (date_sale) as data_sale
from tbsales
join tbsales_tribute on
(tbsales_tribute.emp = tbsales.emp and tbsales_tribute.sale = tbsales.sale)
where tbsales.emp = 1
and tbsales_tribute.type = 5

Which of these queries is more optimized?

(a friend told me that we should always use the sybase key join instead of join, key join the reserved word always makes the query more optimized, so pe truth? where I can find material about?)

View Entire Topic
Former Member

The three queries are equivalent for the optimizer and the execution part. You may need additional indexes and/or cache warming. Check the first query execuion using the Index Consultant and the Plan Viewer.