> Say I have a bunch of records in a table with a bunch of fields. One of
> those fields is cluster_id. It is not unique. However, I want to make a
> unique set. I want one record for each cluster_id value. I don't care
> which record that is.
>
> Right now, I do:
> SELECT DISTINCT cluster_id FROM my_table
>
> Then, for each of those I do:
> SELECT * FROM my_table WHERE cluster_id=$cluster_id
>
> I take the first record of the response and continue. This is very slow
> because I'm accesing the database thousands of times instead of once.
An improvement (perhaps) would be to add LIMIT 1;
e.g. select * from my_table where cluster_id=$cluster_id LIMIT 1;
I assume that asking through SQL to just fetch 1 tuple, is better that getting all of
them and then using the 1st
> Also, I would like to SELECT into another table. The MySQL docs only say
> how to select into a file. This is not really what I want. What I do now
> is SELECT and then INSERT each row.
That is in the INSERT functionality:
INSERT INTO my_table SELECT bla bla bla;
Just be careful: you cannot insert into the same table from which you select.
regards,
thalis
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php