?
Solved

select varchar fields in table1 that are not in table2

Posted on 2013-11-16
2
Medium Priority
?
385 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
Amar Bardoliwala earned 2000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 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