php


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 |

Related Links

Unable to get textarea from PHP contact form [duplicate]
return 'None' from APNs in python using pyapns
Driver [driver] not supported
Symfony - Attempted to load class - ClassNotFoundException
Receiving SOAP process with PHP
Fire and event after the user is logged in for certain amount of time
PHP DateInterval equality
SUM of columns while grouping by other column
Calling a method of a controller in Altorouter
Get a Primary Key from <a href> for it's content to be visible on another page with Code Igniter
examen-system/ PHP and Smarty
How do i pull in only the first and third Tuesdays of current month into a form field in PHP?
How to use a particular port to send or get updates via webhook to telegram?
Nesting PHP using if statement
Why FILTER_SANITIZE_EMAIL is not removing invalid characters from invalid email address?
Async/Thread on PHP7 with FPM

Categories

HOME
qt
blast
bokeh
exchange-server
couchdb
bots
writefile
tcsh
message-queue
dafny
plpgsql
risk-management
web2py
mosquitto
cisco
stack-overflow
twitter-oauth
graphdb
orc
google-awareness
asp.net-core-1.0
cocos2d-android
tfsbuild
xsl-fo
angular2-highcharts
azure-machine-learning
pst
react-dnd
raima
jpa-2.1
hevc
onchange
bobo-browse.net
docx4j
d3.js-v4
xenapp
es6-modules
reporting
epplus
osx-lion
devtools
formsauthenticationticket
jade4j
praat
stat
right-click
game-center
coverage.py
notesview
httphandler
code-push
daz3d
realstudio
xcglogger
algebra
mobile-angular-ui
glassfish-4.1
fitbit
annotatorjs
petsc
android-sdcard
eclemma
codecharge
apple-configurator
android-async-http
utf-16
voronoi
helm
textpattern
linuxbrew
stack-smash
decidable
screen-orientation
gluon-desktop
ngcordova
python-curses
mod-auth-openidc
jolie
microsoft-expression-web
rebar
ildasm
igor
visual-c++-2012
android-2.3-gingerbread
senchatouch-2.4
xulrunner
jack
xmi
accountmanager
gpu-programming
jmenubar
visual-c++-2005
lru
hints
insertion
semicolon
jbox2d
linkbutton
clearinterval
kobold2d
memory-pool
infopath-2007
groovy-console
kohana-auth
servlet-container
django-pagination
fgetc

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App