473,405 Members | 2,171 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,405 software developers and data experts.

need help with LEFT JOIN statemen

I'm trying to left join a table where there are two identical fields

I want to select all records in a field from the left table and only
those records from the identical field of the right table which are not
bigger or smaller then 1

both field in the tables are integer data type

Can someone help

I tried this code but it does not work, I'm not sure if I can use these
operators <>
__________________________________________
SELECT Table1.field1,Table2.field1
FROM Table1 RIGHT JOIN Table2 ON (Table1.field1 = Table2.field2) AND
not (Table1.field1 (Table2.field2+1)) AND not (Table1.field1 <
(Table2.field2-1))
__________________________________________

Aug 14 '06 #1
2 1307
Stu
Try this:

DECLARE @Table1 TABLE (Col1 int)
DECLARE @Table2 TABLE (Col1 int)

INSERT INTO @Table1
SELECT 1
UNION ALL
SELECT 2
UNION ALL
SELECT 3
UNION ALL
SELECT 9
INSERT INTO @Table2
SELECT 0
UNION ALL
SELECT 1
UNION ALL
SELECT 2
UNION ALL
SELECT 3
UNION ALL
SELECT 4
UNION ALL
SELECT 5
SELECT t1.col1, t2.col1
FROM @Table1 t1
LEFT JOIN @Table2 t2 ON t1.col1 BETWEEN t2.col1-1 AND t2.col1+1
It that ain't it, post DDL and sample data.

HTH,
Stu

eu*******@hotmail.com wrote:
I'm trying to left join a table where there are two identical fields

I want to select all records in a field from the left table and only
those records from the identical field of the right table which are not
bigger or smaller then 1

both field in the tables are integer data type

Can someone help

I tried this code but it does not work, I'm not sure if I can use these
operators <>
__________________________________________
SELECT Table1.field1,Table2.field1
FROM Table1 RIGHT JOIN Table2 ON (Table1.field1 = Table2.field2) AND
not (Table1.field1 (Table2.field2+1)) AND not (Table1.field1 <
(Table2.field2-1))
__________________________________________
Aug 14 '06 #2
boa
* eu*******@hotmail.com wrote, On 14.08.2006 19:42:
I'm trying to left join a table where there are two identical fields

I want to select all records in a field from the left table and only
those records from the identical field of the right table which are not
bigger or smaller then 1

both field in the tables are integer data type

Can someone help

I tried this code but it does not work, I'm not sure if I can use these
operators <>
__________________________________________
SELECT Table1.field1,Table2.field1
FROM Table1 RIGHT JOIN Table2 ON (Table1.field1 = Table2.field2) AND
not (Table1.field1 (Table2.field2+1)) AND not (Table1.field1 <
(Table2.field2-1))
__________________________________________
select t1.f1, t2.f1
from t1, t2
where t1.f1 between t2.f1 - 1 and t2.f1 + 1

Is that what you meant? :-)

HTH
Bjørn

Aug 14 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me...
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,...
1
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"...
1
by: MK Randall | last post by:
We're losing a Sybase datasource and need to pull from an identical DB2 database until the SQL Server becomes available later on this year. If someone could read through the query and let me know...
1
by: imranpariyani | last post by:
Hi i have a severe performance problem with one of my views which has 6 to 8 joins .. any help will be appreciated.. the view is: CREATE OR REPLACE VIEW thsn.trade_view AS SELECT...
3
by: mlcampeau | last post by:
Hi guys, I am trying to run a query that calculates when employees become eligible for supplemental vacation. This occcurs once the employee has reached 5, 10, 15, etc years of service. I got the...
2
by: speavey | last post by:
When I run this query, I get an ORDER BY error "Incorrect syntax near the keyword 'ORDER'. I've bolded it below. If I take the ORDER by out then it works correctly, but I need the ORDER BY...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.