List:General Discussion« Previous MessageNext Message »
From:Michael Stassen Date:August 17 2004 2:56pm
Subject:Re: SQL question, SELECT DISTINCT
View as plain text  
How about

   INSERT INTO original_table
   SELECT MAX(f1), f2, f3 FROM new_table GROUP BY f2, f3;

Michael

Stephen E. Bacher wrote:
> I had a similar problem, but my criteria for selecting the
> value of "f1" was different; it's a date field and I wanted
> only the rows with the most recent date value in that field,
> so only the "latest" of otherwise identical entries got inserted.
> 
> I ended up doing something like this:
> 
> create temporary table temp_table (
>  t_f1 date,
>  t_f2 varchar(100) unique,
>  t_f3 varchar(100) unique
> );
> 
> insert ignore into temp_table
>  select f1,f2,f3 from new_table
>  order by f1 desc;
> 
> insert into original_table
>  select * from temp_table;
> 
> If there is a better way to do this, I would like to
> know about it.
> 
>  - seb
> 
> 

Thread
Can connect with PHP to MYSQLleegold13 Aug
  • Re: Can connect with PHP to MYSQLsuomi13 Aug
  • Re: Can connect with PHP to MYSQLWesley Furgiuele13 Aug
    • Re: Can connect with PHP to MYSQLleegold13 Aug
      • Re: Can connect with PHP to MYSQLAndreas Ahlenstorf13 Aug
        • SQL question, SELECT DISTINCTleegold16 Aug
          • Re: SQL question, SELECT DISTINCTSGreen16 Aug
            • Re: SQL question, SELECT DISTINCTleegold16 Aug
              • T-SQL SUM() Overflow?David Mohorn16 Aug
              • Re: SQL question, SELECT DISTINCTSGreen16 Aug
                • Re: SQL question, SELECT DISTINCTleegold16 Aug
                  • Re: SQL question, SELECT DISTINCTMichael Stassen16 Aug
RE: T-SQL SUM() Overflow?Martin Gainty16 Aug
Re: SQL question, SELECT DISTINCTleegold16 Aug
  • Re: SQL question, SELECT DISTINCTMichael Stassen16 Aug
    • Re: SQL question, SELECT DISTINCTleegold16 Aug
Re: SQL question, SELECT DISTINCTleegold16 Aug
Re: SQL question, SELECT DISTINCTStephen E. Bacher17 Aug
  • Re: SQL question, SELECT DISTINCTMichael Stassen17 Aug