Solved

MySQL - Identifying records on one table but not on another

Posted on 2009-07-02
3
439 Views
Last Modified: 2013-12-13
I have two tables that have some columns in common.including a unique identifying key which is shared by both. One table has 'x' rows, the other has 'x-y' rows - I want to be able to construct a query that will show me the rows that are on table 1, but not on table 2 .... is this possible?
0
Comment
Question by:me_patrick
[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
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 24763348
this will do
select t1.*
  from table1 t1
  left join table2 t2
    on t1.key = t2.key
  where t2.key is null

Open in new window

0
 
LVL 92

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 250 total points
ID: 24763360
In SQL Server you would use:

SELECT t1.*
FROM Table1 t1 LEFT JOIN
      Table2 t2 ON t1.ID = t2.ID
WHERE t2.ID IS NULL

The MySQL syntax should be similar...
0
 

Author Closing Comment

by:me_patrick
ID: 31599191
Thanks guys - spot on.
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

696 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