At 02:37 PM 8/1/2006, Cesar David Rodas Maldonado wrote:
Hello to all!

How can I optimize this query

select * from table where col1 = 5 && col2 = 15;

Put both fields in the same index index. The first index should be the column with the least unique values (col1 by your example).


If I  know that col2 I have 150000 rows and col1 I have just 100 rows, I
know that because I save that data in another table.

You could just do:

select count(distinct col1) from table;
select count(distinct col2) from table;

to get the number of distinct values in each  column.


How can I do for search first where is minus number of result?


Not sure what you mean by this, but if you want rows where col1 is negative just try:

select * from table where col1 < 0



The two columns are indexes.

Yes but probably you are using 2 different indexes. Putting both columns in the same index will make the query faster because you are searching on both columns.

Mike
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

  • Optimization Cesar David Rodas Maldonado
    • Re: Optimization mos

Reply via email to