PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 15, 2022

[FIXED] how to copy only distinct values from one table to another in Mysql?

 January 15, 2022     mysql, phpmyadmin     No comments   

Issue

I have a MySql database round-about 2.5GB,

The table[A] has following columns, |anoid| |query| |date| |item-rank| |url|

I have just created another table[b] having columns only |query| and |date|

I want to insert all the distinct records in query column, with it's respective date, from Table[A] to [B], is there any fast query?


Solution

Use INSERT INTO ... SELECT:

INSERT INTO Tableb(query, date)
SELECT query, MAX(Date) AS MAXDate
FROM Tablea
GROUP BY query

This will give you distinct query with the most recent date.



Answered By - user8608154
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing