Belajar dulu gan |
Pertama buat dahulu table mobile_system
CREATE TABLE IF NOT EXISTS `mobile_system` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL, `detail` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
INSERT INTO `mobile_system` (`id`, `name`, `detail`) VALUES (NULL, 'Ios', ''), (NULL, 'Android', ''), (NULL, 'BB', ''), (NULL, 'Palm', ''), (NULL, 'Win', ''), (NULL, 'Firefox OS', ''), (NULL, 'Meer', ''), (NULL, 'Tizen', '');
CREATE TABLE IF NOT EXISTS `phonegap_system` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`sys` int(11) NOT NULL,
PRIMARY KEY (`id`)
)
`id` int(11) NOT NULL AUTO_INCREMENT,
`sys` int(11) NOT NULL,
PRIMARY KEY (`id`)
)
input dengan system2 yang di support oleh phonegap yaitu
IOS, BB, Android, Windows, palm..
dengan menjalankan
SELECT * FROM `mobile_system` s,phonegap_system p where s.id=p.sysatau
SELECT s.id, s.name FROM `mobile_system` ssaya akan mendapatkan 5 data, tetapi bagaimana sisanya seperti FF Os, Meer dan Tizen??
left join phonegap_system p
on s.id=p.sys
SELECT s.id, s.name FROM `mobile_system` s
left join phonegap_system p
on s.id=p.sys
where p.id is NULL
saya suka miss tentang formatnya.. jadi sekedar reminder
select [list yang akan tampil] from [table1 dengan alias T1] left join [table2 dengan alias T2] on [T1].id = [T2].id where [T2].id is NULL
yang saya kasi tebal adalah yang paling terpenting!! Tetapi cara berikut ini tidak di rekomendasikan walau hasilnya sesuai dengan keinginan
SELECT s.id, s.name FROM `mobile_system` s
where s.id not in (select sys from phonegap_system )
subquery dikabarkan suka bermasalah dan kerjanya agak boros memori..where s.id not in (select sys from phonegap_system )
sumber :
http://stackoverflow.com/
notes
Unfortunately it seems to be a issue with MySql usage of "NOT IN" clause, the screen-shoot below shows the sub-query option returning wrong results:
Joins are generally faster (in MySQL), but you should also consider your indexing scheme if you find that it's still moving slowly. Generally, any field setup as a foreign key (using INNODB) will already have an index set. If you're using MYISAM, make sure that any columns in the ON statement are indexed, and consider also using any columns in the WHERE clause.
http://stackoverflow.com/questions/1519272/mysql-not-in-query
Joins are generally faster (in MySQL), but you should also consider your indexing scheme if you find that it's still moving slowly. Generally, any field setup as a foreign key (using INNODB) will already have an index set. If you're using MYISAM, make sure that any columns in the ON statement are indexed, and consider also using any columns in the WHERE clause.
Tidak ada komentar:
Posting Komentar