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

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]

Categories

HOME
mod-rewrite
android-studio
xcode8.1
filesize
hdfs
website
tcp
header
moodle-api
gprs
cdi
sympy
specifications
reportviewer
clickable-image
alljoyn
documentum
spring-amqp
feature-extraction
xbap
ex
orange-api
boomi
salt-cloud
http-authentication
multiple-tables
spring-ldap
acl
eclipse-emf
react-dnd
jpa-2.1
publishing
argv
epplus
counting
cmis
db2-luw
amazon-kms
textmate2
fastlane
variable-variables
python-sounddevice
right-click
fluid-mac-app-engine
sendinput
intellij-lombok-plugin
webalizer
nothing
openstack-glance
word-2007
pecl
business-rules
maatwebsite-excel
msg
spring-mongo
mathml
ajaxmin
strpos
distributed-cache
verisign
ui4j
bjam
gluon-desktop
css-paged-media
swagger-maven-plugin
algebraixlib
clarion
prism-4
rfc5545
createfile
google-hangouts
lifetime
datagridcomboboxcolumn
iplimage
inputbox
windows-rt
relationships
mobile-country-code
category-theory
android-2.3-gingerbread
senchatouch-2.4
meteor-collections
ivalueconverter
usb-flash-drive
spring-social-linkedin
strdup
xsd2code
rautomation
google-code-prettify
lru
playorm
sfinae
opends
channelfactory
tessellation
iphone-sdk-3.1.3

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App