Mysql fetch records common records as well uncommon records

I have 5 tables (amazon,ebay,opencart,sears,jet) I want common records from all table on first priority then common records from any of the two ya three tables tables then uncommon records.

my tables and its data are like:

CREATE TABLE IF NOT EXISTS amazon (
id int(11) NOT NULL AUTO_INCREMENT,
a_upc varchar(50) DEFAULT NULL,
a_sku varchar(50) DEFAULT NULL,
a_title varchar(50) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

— Dumping data for table amazon

INSERT INTO amazon (id, a_upc, a_sku, a_title) VALUES
(1, ‘upc_a’, ‘sku1’, ‘title_a’),
(2, ‘upc1’, ‘sku_a’, ‘title_a_1’);

CREATE TABLE IF NOT EXISTS jet (
id int(11) NOT NULL AUTO_INCREMENT,
j_upc varchar(50) DEFAULT NULL,
j_sku varchar(50) DEFAULT NULL,
j_title varchar(50) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

— Dumping data for table jet

INSERT INTO jet (id, j_upc, j_sku, j_title) VALUES
(1, ‘upc1’, ‘sku_j’, ‘title_j’),
(2, ‘upc_j’, ‘sku_j_1’, ‘title1’);

CREATE TABLE IF NOT EXISTS ebay (
id int(11) NOT NULL AUTO_INCREMENT,
e_upc varchar(50) DEFAULT NULL,
e_sku varchar(50) DEFAULT NULL,
e_title varchar(50) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

— Dumping data for table ebay

INSERT INTO ebay (id, e_upc, e_sku, e_title) VALUES
(1, ‘upc_e’, ‘sku1’, ‘title_e’),
(2, ‘upc1’, ‘sku_e’, ‘title_e_1’),
(3, ‘upc_e_1’, ‘sku2’, ‘title1’);

CREATE TABLE IF NOT EXISTS opencart (
id int(11) NOT NULL AUTO_INCREMENT,
o_upc varchar(50) DEFAULT NULL,
o_sku varchar(50) DEFAULT NULL,
o_title varchar(50) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

— Dumping data for table opencart

INSERT INTO opencart (id, o_upc, o_sku, o_title) VALUES
(1, ‘upc_a’, ‘sku1’, ‘title_o’),
(2, ‘upc1’, ‘sku_o’, ‘title1’);

CREATE TABLE IF NOT EXISTS sears (
id int(11) NOT NULL AUTO_INCREMENT,
s_upc varchar(50) DEFAULT NULL,
s_sku varchar(50) DEFAULT NULL,
s_title varchar(50) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

— Dumping data for table sears

INSERT INTO sears (id, s_upc, s_sku, s_title) VALUES
(1, ‘upc1’, ‘sku_s’, ‘title_s’),
(2, ‘upc_s’, ‘sku_s_1’, ‘title_s_1’);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s