MYSQL Create table with Unique values
I am trying to UPDATE my table from another table. I would like to ignore duplicates and also delete any matches in that table. Source Table Table 1 Table 2 Customer | Address Customer | Address Customer | Address __________________ __________________ __________________ Mike 123 Main Mike 123 Main Bob 999 1st Steve 456 Maple Steve 456 Maple John 789 Elm John 789 Elm Bob 999 1st For example, Table 2 will only have the unique entry after "Source Table" is compared to Table 1. I am using MYSQL/PHP. Any direction is greatly appreciated.
SQL Fiddle MySQL 5.5.32 Schema Setup: CREATE TABLE Source (`Customer` varchar(5), `Address` varchar(9)) ; INSERT INTO Source (`Customer`, `Address`) VALUES ('Mike', '123 Main'), ('Steve', '456 Maple'), ('John', '789 Elm'), ('Bob', '999 1st'), ('Bob', '999 1st') ; CREATE TABLE Table1 (`Customer` varchar(5), `Address` varchar(9)) ; INSERT INTO Table1 (`Customer`, `Address`) VALUES ('Mike', '123 Main'), ('Steve', '456 Maple'), ('John', '789 Elm') ; CREATE TABLE Table2 (`Customer` varchar(5), `Address` varchar(9)) ; DELETE FROM Table2; INSERT INTO Table2 (`Customer`, `Address`) SELECT DISTINCT Customer, Address FROM Source WHERE NOT EXISTS (SELECT 1 FROM Table1 WHERE Source.Customer = Table1.Customer) Query 1: SELECT * FROM Table2 Results: | CUSTOMER | ADDRESS | |----------|---------| | Bob | 999 1st |
Highcharts doesn't show all contents of x-axis
Dynamic table with php pdo and two foreach
PHP color of the first line in a loop
Decrypt Rijndael with Passphrase in PHP
WP-API Get Posts After a Specific Date
How Do i Print last 10 days using php? [closed]
MySQL: Joining table duplicates SUM()
how to manuplate the google api php client
Unable to get cookie in construct function
How to loop through Models find from Where clause?
Trying to keep session with curl login in twitter
Code start and end in specific time
Return total values of each column after using datepicker to select a start and end date
file_put_contents on multiple request of XML data
How can i change this select sql statement into another select sql?
This code always return $id but not $first_name [duplicate]