473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Help with Outer Join

3
I am having problems figuring out how to accomplish something...

TABLE 1
> Field_ID (prm key)
> Name

TABLE 2
> ID (prm key)
> Field_ID (prm key)
> Stuff

I just want to return all the rows from TABLE 1 that DO NOT have a cooresponding match in TABLE 2.

For instance, this works... but is very slow. Is there a simple way to do this? I can't seem to figure out how to do a join that returns all rows from a table where the records do not match.

select * from TABLE1 where field_id NOT IN (select distinct field_id from TABLE2);
Feb 21 '07 #1
4 1250
ronverdonk
4,258 Expert 4TB
Don't know if this is faster, but try it out

Expand|Select|Wrap|Line Numbers
  1. SELECT table1.id, table1.xx from table1
  2.   LEFT JOIN table2 ON(table1.id=table1.id) 
  3.   WHERE table2.id IS NULL;
Ronald :cool:
Feb 21 '07 #2
vbrich
3
Thanks for the post. It actually took twice as long that way. I might have to stick with the first query (about 30 seconds). I was just hoping there was an easier way.
Feb 21 '07 #3
ronverdonk
4,258 Expert 4TB
Have you ever tried to use the EXPLAIN option in your MySQL SELECT statement to see what table takes most of the time?

Ronald :cool:
Feb 21 '07 #4
vbrich
3
Nope. Never tried, but I don't do sql that often if you couldn't tell. I'll read up on it a little bit and compare these queries a bit more.

The primary reason for my post was to see if there was some sort of magical outer join that I was unaware of. I will play around with this a bit, but it sounds like it is going to be a large query no matter which way I slice it.

10k rows in table 1
20k rows in table 2 that reference the prm key from table 1
I need all the rows from table 1 that are not referenced in table2

Thanks
Feb 23 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Justin Hennessy | last post by:
Hi all, I am working with a computer hardware asset database and I am trying to get information out of it for each PC in my organisation. Here is the basic table structure: Table1 -> Table2...
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
3
by: Prem | last post by:
Hi, I am having many problems with inner join. my first problem is : 1) I want to know the precedance while evaluating query with multiple joins. eg. select Employees.FirstName,...
5
by: David Logan | last post by:
Hello, I am trying to construct a query across 5 tables but primarily 3 tables. Plan, Provider, ProviderLocation are the three primary tables the other tables are lookup tables for values the...
8
by: Matt | last post by:
Hello I have to tables ar and arb, ar holds articles and a swedish description, arb holds descriptions in other languages. I want to retreive all articles that match a criteria from ar and...
28
by: stu_gots | last post by:
I have been losing sleep over this puzzle, and I'm convinced my train of thought is heading in the wrong direction. It is difficult to explain my circumstances, so I will present an identical...
4
by: thilbert | last post by:
All, I have a perplexing problem that I hope someone can help me with. I have the following table struct: Permission ----------------- PermissionId Permission
7
by: Steve | last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three "Left Outer Joins" in order to return every transaction for a specific set of criteria. Using three "Left Outer Joins"...
2
by: Notgiven | last post by:
I have three tables: table1: table2_ID table3_ID complete table3: table3_ID name
5
by: Bob Stearns | last post by:
The following query runs very slowly compared to other queries on my system. If I read the explain plan and its data correctly, it is due to a table scan on animals caused by the join separated...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.