Solved

select varchar fields in table1 that are not in table2

Posted on 2013-11-16
2
382 Views
Last Modified: 2013-11-17
CREATE TABLE `saved_searches` (
  `savedSearchesID` bigint(20) unsigned NOT NULL auto_increment,
  `savedSearchesDefaultUsername` varchar(50) default NULL,
  PRIMARY KEY  (`savedSearchesID`)
);

 CREATE TABLE `a_messages` (
  `a_messages_id` int(11) NOT NULL auto_increment,
  `profile_id` varchar(20) default NULL,
  `message_id` bigint(20) default NULL,
  `this_user` varchar(20) default NULL,
  PRIMARY KEY  (`a_messages_id`),
  UNIQUE KEY `unique_message_id` (`message_id`)
) ENGINE=MyISAM AUTO_INCREMENT=51 DEFAULT CHARSET=utf8;

saved_searches.savedSearchesDefaultUsername is the same as a_messages.profile_id
want to select all the
saved_searches.savedSearchesDefaultUsername
that are not yet in
a_messages.profile_id

sample data
saved_searches.savedSearchesDefaultUsername
bob
sarah
susan

 a_messages.profile_id
bob

so only select
sarah and susan
0
Comment
Question by:rgb192
2 Comments
 
LVL 11

Accepted Solution

by:
Amar Bardoliwala earned 500 total points
ID: 39654389
Hello rgb192,

You can write your query as following

SELECT saved_searches.savedSearchesDefaultUsername
FROM saved_searches
WHERE NOT
EXISTS (

SELECT 1
FROM a_messages
WHERE a_messages.profile_id = saved_searches.savedSearchesDefaultUsername
)

Open in new window


Hope, this will help you.

Thank you.

Amar Bardoli wala
0
 

Author Closing Comment

by:rgb192
ID: 39654968
thanks
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question