Solved

select varchar fields in table1 that are not in table2

Posted on 2013-11-16
2
378 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error connecting to mysql on localhost 3 50
mysql Encryption with PHP 8 95
PHP connection to remote AWS MySQL RDS 4 67
MySQL  on Tomcat 8 26
I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
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 …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now