Creating A Left Join When Selecting From 3 Tables

Nov 30, 2007



Hi,
I was wanting to know if it is possible to create a left join when selecting from 3 seperate tables.

Select p.Project_name, p.project_id, cp.email_display_name, te.Mon
FROM tblProject p, tblCorpPerson cp, tblTimeEntry te
WHERE p.Project_ID = te.Project_ID
AND p.Person_ID = @PersonID
AND cp.Person_ID = p.Person_ID


I need to return all rows from tblProject, and any matching project_id's from tblTimeEntry.

Any ideas or suggestions?

Thanks

View 24 Replies


ADVERTISEMENT

How To Join 3 Tables Using Left Or Right Join Keyword?

Aug 17, 2007

Hi guys,

I'll appreciate any help with the following problem:

I need to retrieve data from 3 tables. 2 master tables and 1 transaction table.

1. Master table TBLOC contain 2 records :
rcd 1. S01
rcd 2. S02

2. Master table TBCODE contain 5 records:

rcd 1. C1
rcd 2. C2
rcd 3. C3
rcd 4. C4
rcd 5. C5

3. Transaction table TBITEM contain 4 records which link to 2 master table:
rcd 1. S01, C1, CAR

rcd 2. S01, C4, TOY
rcd 3. S01, C5, KEY
rcd 4. S02, C2, CAR



I use Left Join & Right Join to retrieve result below (using non-ASNI method) but it doesn't work.

Right Join method:


SELECT C.LOC, B.CODE, A.ITEM FROM TBITEM A RIGHT JOIN TBCODE B ON A.CODE = B.CODE

RIGHT JOIN TBLOC C ON A.LOC = C.LOC

GROUP BY C.LOC, B.CODE, A.ITEM ORDER BY C.LOC, B.CODE



When I use Non-ASNI method it work:



SELECT C.LOC, B.CODE, A.ITEM FROM TBITEM A, TBCODE B, TBLOC C

WHERE A.CODE =* B.CODE AND A.LOC =* C.LOC

GROUP BY C.LOC, B.CODE, A.ITEM ORDER BY C.LOC, B.CODE

Result:

LOC CODE ITEM
-----------------------------
S01 C1 NULL
S01 C2 NULL
S01 C3 CAR
S01 C4 TOY
S01 C5 KEY
S02 C1 NULL
S02 C2 CAR
S02 C3 NULL
S02 C4 NULL
S02 C5 NULL


Please Help.

Thanks.






View 3 Replies View Related

Left Join Vs Left Outer Join Syntax Generates Different Execution Plans

Apr 16, 2008



Anyone know why using

SELECT *
FROM a LEFT OUTER JOIN b
ON a.id = b.id
instead of

SELECT *
FROM a LEFT JOIN b
ON a.id = b.id

generates a different execution plan?

My query is more complex, but when I change "LEFT OUTER JOIN" to "LEFT JOIN" I get a different execution plan, which is absolutely baffling me! Especially considering everything I know and was able to research essentially said the "OUTER" is implied in "LEFT JOIN".

Any enlightenment is very appreciated.

Thanks

View 5 Replies View Related

How To Use Left Outer Join In Two Tables?

Nov 8, 2007

Hi all,

I need a small help in creating a join query in sql.

My two tables are A and B. A has got columns id, dname, counter and
date. B has got two columns link and date. The primary key of A
is the column Id whereas in table B, both are primary keys(composite key).

I need to get the records (id,dname,counter) from A which has no
corresponding link in table B.

To be precise, If the table A has fields (id,dname,counter) (1,abc,2000)
and if table B has no record for abc, this row should be returned from A.I hope using left outer join will help me in getting my desired result.I hope someone will be able to help me out.

Thanking all in advance for your valuable time.

View 1 Replies View Related

Issues With LEFT Join On Four Tables

Jul 20, 2005

Hi Folks,Lets assume I have three tables. Their layout is as follows. Pleasenote that tblPeople does not have an entry for Denver (this is myproblem)tblCity_________________CityName OCIDLA 1Denver 2tblCars_________________OCID CarVolume1 300,0002 200,000tblPeople_________________OCID PeopleVolume1 1,200,345tblDogs_________________OCID DogVolume1 234,9872 445,987I'd like to run a quiery that returns the following data set:CityName OCID CarVolume PeopleVolume DogVolumeLA 1 300000 1200345 234987Denver 2 200000 null or 0 445997My problem is the people table. Since there not entry for Denver, myquery is returning only a row for LA, nothing for Denver. Here's whtmy query looks likeSelect tblCity.CityName, tblCity.OCID, tblCars.CarVolume,tblPeople.PeopleVolume, tblDogs.DogVolumeFROM tblCityLEFT JOIN tblCars on tblCity.OCID = tblCars.OCIDJOIN tblPeople on tblCars.OCID = tblPeople.OCIDJOIN tblDogs on tblPeople.OCID = tblDogs.OCIDThis returns the following:CityName OCID CarVolume PeopleVolume DogVolumeLA 1 300000 1200345 234987I need this query to return a row for Denver as well. Any thoughtsanyone?Your insight is greatly appreciated. ericlangland at hotmail.com

View 1 Replies View Related

SSMS Express: Creating Parent-Child Table Via LEFT OUTER JOIN - Error Message 156

May 22, 2006

Hi all,

I got an error message 156, when I executed the following code:

////--SQLQueryParent&Child.sql---////////

Use newDB

GO

----Creating dbo.Person as a Parent Table----

CREATE TABLE dbo.Person

(PersonID int PRIMARY KEY NOT NULL,

FirstName varchar(25) NOT NULL,

LastName varchar(25) NOT NULL,

City varchar(25) NOT NULL,

State varchar(25) NOT NULL,

Phone varchar(25) NOT NULL)

INSERT dbo.Person (PersonID, FirstName, LastName, City, State, Phone)

SELECT 1, "George", "Washington", "Washington", "DC", "1-000-1234567"

UNION ALL

SELECT 2, "Abe", "Lincoln", "Chicago", "IL", "1-111-2223333"

UNION ALL

SELECT 3, "Thomas", "Jefferson", "Charlottesville", "VA", "1-222-4445555"

GO

----Creating dbo.Book as a Child table----

CREATE TABLE dbo.Book

(BookID int PRIMARY KEY NOT NULL,

BookTitle varchar(25) NOT NULL,

AuthorID int FOREIGN KEY NOT NULL)

INSERT dbo.Book (BookID, BookTitle, AuthorID)

SELECT 1, "How to Chop a Cherry Tree", 1

UNION ALL

SELECT 2, "Valley Forge Snow Angels", 1

UNION ALL

SELECT 3, "Marsha and ME", 1

UNION ALL

SELECT 4, "Summer Job Surveying Viginia", 1

UNION ALL

SELECT 5, "Log Chopping in Illinois", 2

UNION ALL

SELECT 6, "Registry of Visitors to the White House", 2

UNION ALL

SELECT 7, "My Favorite Inventions", 3

UNION ALL

SELECT 8, "More Favorite Inventions", 3

UNION ALL

SELECT 9, "Inventions for Which the World is Not Ready", 3

UNION ALL

SELECT 10, "The Path to the White House", 2

UNION ALL

SELECT 11, "Why I Do not Believe in Polls", 2

UNION ALL

SELECT 12, "Doing the Right Thing is Hard", 2

GO

---Try to obtain the LEFT OUTER JOIN Results for the Parent-Child Table

SELECT * FROM Person AS I LEFT OUTER JOIN Book ON I.ID=P.ID

GO

////---Results---//////

Msg 156, Level 15, State 1, Line 5

Incorrect syntax near the keyword 'NOT'.

////////////////////////////////////////////////////

(1) Where did I do wrong and cause the Error Message 156?

(2) I try to get a Parent-Child table by using the LEFT OUTER JOIN via the following code statement:

Msg 156, Level 15, State 1, Line 5

Incorrect syntax near the keyword 'NOT'.

Can I get a Parent-Child table after the error 156 is resolved?

Please help and advise.

Thanks,

Scott Chang

View 9 Replies View Related

Got Problem When Combines Tables Using Left Join

Mar 27, 2007

Hi,

I'm having problem with left join ...

Let's say i've these following tables

academic
ID | year | level | m_l
----------------------------------------------
147 | 2006 | dip | 20
148 | 2006 | dip | 12


course
ID | year | level | course_desc | m_l
----------------------------------------------
147 | 2006 | dip | k | 7
147 | 2006 | dip | b | 11


Hint
----
(1) see course table, select sum(m_l) from course where ID=147 and year=2006 and level='dip' = 18
(2) after query from (1), if user select ID=147, year=2006, level=dip, then m_l receiving 2 or less only (0,1,2).


What i've done shown as follow:-

SELECT a.ID, a.Year, a.Level, a.m_l - b.m_l [value_left_in_course]
FROM
academic a
LEFT JOIN
(SELECT SUM(m_l) [m_l] FROM course
where ID=147 and year=2006 and level='dip'
GROUP BY ID) b
ON a.ID = b.ID
where a.ID=147 and a.year=2006 and a.level='dip'

the result is
ID | year | level | value_left_in_course
----------------------------------------------
147 | 2006 | dip | 2

MY PROBLEM IS WHEN NO ROWS in course when ID=148, then i'm query as above the result is
ID | year | level | value_left_in_course
----------------------------------------------
147 | 2006 | dip | (null)


How to writing SQL to changing (null), then the result shown as follow?
ID | year | level | value_left_in_course
----------------------------------------------
147 | 2006 | dip | 12

View 5 Replies View Related

Two Tables With Left Outer Join && Where Clause

Oct 29, 2007

Hello,I'm trying to link two tables... one for Employees and the other forTimecardsI need to get a list of employees that do not have timecards on anSPECIFIC DATEI tried the follonwingSELECT Employess.EmployeeIDFROM Employees LEFT OUTER JOIN Timecards on Employees.EmployeeID =Timecards.lmpEmployeeIDWHERE lmpEmployeeID is NULL and lmpTimecardDate = '10/24/2007'But it doesn't work. However, when I comment the date condition out(lmpTimecardDate = '10/24/2007') it works all right but It's not whatI needAnother interesting point... if I use the following query... it worksall rightSELECT Employess.EmployeeIDFROM EmployeesWHERE Employees.EmployeeID not in (select Timecards.EmployeeID fromTimecardswhere TimecardDate = '10/24/2007')I'd like to be able to use the Left Outer Join option.... Am I doingsomething wrong?... or is it that if It doesn't like the condition I'musgin in the WHERE clause (TimecardDate = '10/24/2007')Thanks for your helpPablo

View 3 Replies View Related

SQL Server 2014 :: 2 Tables Combined Left Join To Primary Key Of A 3 Third Table

Sep 1, 2014

Looking to improve performance of the following code.

It basically generates future days for each dog. So there is a dog table and a day table with every day.

These 2 table cross join and then fill in missing rows. As time moves i will fill in further future dates but will need the initial insert to be a reasonable query.

All columns are covered by index's but the queries at the end take quite a long time. I would hope for index scan to just point out the missing rows especially on the final query.

How to make the last query as fast as possible.

IF OBJECT_ID('dbo.[AllDates]', 'U') IS NOT NULL
DROP TABLE dbo.[AllDates]
CREATE TABLE dbo.[AllDates] (
[Date] date not null PRIMARY KEY
)
;WITH Dates AS

[Code] .....

View 2 Replies View Related

Selecting Rows From Two Tables With JOIN And Ordering Problem

Dec 8, 2007



Hi,

First the environment: two tables A and B.

Table A: ID (unique-identifier)
Table B: ID_A (unique-identifier to A.ID, relation)

DTime (datetime)

Rows (id1 and id2 are Id examples):
A: id1
id2
B: id1 and 12:00:00 (date not important)
id1 and 13:00:00
id2 and 12:00:00

Example:
SELECT A.ID, B.DTIME
FROM A
LEFT JOIN B ON B.ID_A = A.ID
WHERE B.DTime < '14:00:00'
ORDER BY NEWID()

When I run this, I get the three rows of table B. But what I want is to get each table A row once, and get the nearest datetime of WHERE expression from the relation of table B.
So, the result must been two rows, id1 and id2, and id1 with '13:00:00' row because this is the nearest value of '14:00:00'.

How can I do this? DISTINCT trying by A.ID of SELECT, but doesn't work. Also ORDER BY B.DTime will work, but not random by NEWID() anymore.

Thank you.

View 3 Replies View Related

Need Help Creating Outer Join On Multiple Tables

Nov 2, 2005

I'm trying to join 3 tables in an outer join since I am loosing records that need to be included if I only use an inner join. I am pulling data from an MSDE database using the microsoft query tool.

The problem is that I get the message that I can't use an outer join on a query with more than 2 tables, but that can't be right can it?

I'm a SQL code novice so any help would be greatly appreciated!

SELECT
Article.articleId
, Article.articleName
, Article.articleStatus
, Articlegroup_2.ArticlegroupId
, Articlegroup_2.g2_key
, Articlegroup_2.g2_name
, articleGroup.articleGroupId
FROM
HIP.dbo.Article Article, HIP.dbo.articleGroup articleGroup, HIP.dbo.Articlegroup_2 Articlegroup_2
WHERE
articleGroup.articleGroupId = Article.articleGroupId AND
Article.articleGroupId2 = Articlegroup_2.Articlegroup_2_Id

View 5 Replies View Related

Need Help Creating Outer Join On Multiple Tables

Dec 14, 2007

I'm trying to join 2 tables in an outer join, but MS Query won't let me do this because I have another 2 tables included in an inner join ("only two tables are allowed in an outer join"). I am pulling data from an MSDE database using the microsoft query tool.

I'm a SQL code novice so any help would be greatly appreciated!

Here is my existing SQL query (without the new outer join table):

SELECT
Lead_.Country, Lead_.Company_Name, Employee.Full_Name, Lead_.Rn_Create_Date, Lead_.Marketing_Project_Name, Employee_1.Full_Name, Lead_.Comments

FROM
ProductionED.dbo.Employee Employee, ProductionED.dbo.Employee Employee_1, ProductionED.dbo.Lead_ Lead_

WHERE
Employee.Employee_Id = Lead_.Account_Manager_Id AND Employee_1.Employee_Id = Lead_.Created_By_Employee_Id AND ((Lead_.Market_Segment='new'))

View 5 Replies View Related

Left Join Vs Left Outer Join

Apr 7, 2008

Is there any difference between left join and left outer join in sql server 2000?please reply with example if any?
Thanks in advance

View 13 Replies View Related

Left Join Vs Left Outer Join

May 14, 2008

Hi,

Whats the diference between a left join and a left outer Join

View 5 Replies View Related

Integration Services :: How To Perform Left Restricted Join In Merge Join Transformation

May 22, 2015

I have two xml source and i need only left restricted data.

how can i perform left restricted join?

View 2 Replies View Related

Transact SQL :: Difference Between Inner Join And Left Outer Join In Multi-table Joins?

Oct 8, 2015

I was writing a query using both left outer join and inner join.  And the query was ....

SELECT
        S.companyname AS supplier, S.country,P.productid, P.productname, P.unitprice,C.categoryname
FROM
        Production.Suppliers AS S LEFT OUTER JOIN
        (Production.Products AS P
         INNER JOIN Production.Categories AS C

[code]....

However ,the result that i got was correct.But when i did  the same query using the left outer join in both the cases

i.e..

SELECT
        S.companyname AS supplier, S.country,P.productid, P.productname, P.unitprice,C.categoryname
FROM
        Production.Suppliers AS S LEFT OUTER JOIN
(Production.Products AS P
LEFT OUTER JOIN Production.Categories AS C
ON C.categoryid = P.categoryid)
ON
S.supplierid = P.supplierid
WHERE
S.country = N'Japan';

The result i got was same,i.e

supplier     country    productid    productname     unitprice    categorynameSupplier QOVFD     Japan     9     Product AOZBW    97.00     Meat/PoultrySupplier QOVFD    Japan   10     Product YHXGE     31.00     SeafoodSupplier QOVFD     Japan   74     Product BKAZJ    10.00     ProduceSupplier QWUSF     Japan    13     Product POXFU     6.00     SeafoodSupplier QWUSF     Japan     14     Product PWCJB     23.25     ProduceSupplier QWUSF    Japan     15    Product KSZOI     15.50    CondimentsSupplier XYZ     Japan     NULL     NULL     NULL     NULLSupplier XYZ     Japan     NULL     NULL     NULL     NULL

and this time also i got the same result.My question is that is there any specific reason to use inner join when join the third table and not the left outer join.

View 5 Replies View Related

'Left Outer Merge Join' Failing To Join Valid Row

Aug 10, 2007

Scenario:

OLEDB source 1
SELECT ...
,[MANUAL DCD ID] <-- this column set to sort order = 1
...
FROM [dbo].[XLSDCI] ORDER BY [MANUAL DCD ID] ASC


OLEDB source 2
SELECT ...
,[Bo Tkt Num] <-- this column set to sort order = 1
...
FROM ....[dbo].[FFFenics] ORDER BY [Bo Tkt Num] ASC

These two tasks are followed immediately by a MERGE JOIN

All columns in source1 are ticked, all column in source2 are ticked, join key is shown above.
join type is left outer join (source 1 -> source 2)

result of source1 (..dcd column)
...
4-400-8000119
4-400-8000120
4-400-8000121
4-400-8000122 <--row not joining
4-400-8000123
4-400-8000124
...


result of source2 (..tkt num column)
...
4-400-1000118
4-400-1000119
4-400-1000120
4-400-1000121
4-400-1000122 <--row not joining
4-400-1000123
4-400-1000124
4-400-1000125
...

All other rows are joining as expected.
Why is it failing for this one row?

View 1 Replies View Related

Select Command - Left Join Versus Inner Join

Aug 9, 2013

Why would I use a left join instead of a inner join when the columns entered within the SELECT command determine what is displayed from the query results?

View 4 Replies View Related

Right Join Returns Same Results As Left Join

Feb 5, 2015

Why does this right join return the same results as using a left (or even a full join)?There are 470 records in Account, and there are 1611 records in Contact. But any join returns 793 records.

select Contact.firstname, Contact.lastname, Account.[Account Name]
from Contact
right join Account
on Contact.[Account Name] = Account.[Account Name]
where Contact.[Account Name] = Account.[Account Name]

View 3 Replies View Related

Why Is Left Table In LEFT JOIN Limited By Where Clause On Right Table

Jan 25, 2015

-- Why is the left table in a LEFT JOIN limited by the where clause on the right table?eg

DECLARE @LeftTable TABLE (LeftID INT NOT NULL IDENTITY(1, 1), LeftValue INT NULL)
INSERT @LeftTable (LeftValue)
VALUES (111)
INSERT @LeftTable (LeftValue)
VALUES (222)

[code]....

View 2 Replies View Related

SQL LEFT JOIN Help

Jan 26, 2007

I'm trying to join 2 tables. I thought I was getting the correct results but it turns out I'm not.
My Query:
SELECT IVINVA, IVORDN, IVCSLN, IVRESR, IVCITM, CONVERT(varchar(12),CAST(IVIAMT as money),1) AS ExtPrice, CONVERT(varchar(12),CAST(IVPIVC as money),1) AS DistPrice, IVCSUM, IVQYCS, IVDESC, OIRESR, OIDPCT, CONVERT(varchar(12),CAST(IVPIVC - (OIDPCT / 100 * IVPIVC) as money),1) AS NetPrice FROM INVDET1_TBL LEFT JOIN ORDDIS_TBL ON ORDDIS_TBL.OIORDN = INVDET1_TBL.IVORDN AND ORDDIS_TBL.OIRESR = INVDET1_TBL.IVRESR WHERE IVORDN = '0859919' AND IVINVA = '00324024'
 Basically, my problem lies in the seonc condition of the LEFT JOIN. I needed to set the two tables equal my item number, because in some situations I need that logic to get the correct result. It most other cases, that item column in the ORDDIS_TBL is NULL, thus giving me the wrong results. In that case, I would want the JOIN to only be ORDDIS_TBL.OIORDN = INVDET1_TBL.IVORDN, and not include the second part. Is there a way I can condition this with an If statement, If ORDDIS_TBL.OIRESR is Null then do this join, if not, then do this? I'm confused how to get the proper result here.

View 3 Replies View Related

Left Join Help

Jul 7, 2005

I need to make a left join from the freezefile f, to sped s, instead of having f.studentid = s.id in the where clause. Any help??

select f.studentid, f.studentname, f.sex, fs.mealstatus, s.except, s.lre, r.description, g.testid, g.scale_la, g.scale_ma, t.test_name, t.year
from freezefile f, fsapps fs, sped s, regtb_exception r, gqe_scores g, test_info t
where
f.type = 'ADM'
and
s.except = r.code
and
t.test_name = 'ISTEP'
and
t.year = 2004
and
g.testid = t.testid
and
f.studentid = fs.id
and
f.studentid = s.id
and
f.studentid = g.studentid

View 1 Replies View Related

Left/right Join

Aug 2, 2004

i'm shure it's some smal stiupid mistake bat I can't find it, PLZ help.

1)
select komorka from #plantemp
--result

komorka

09
10
I-P
II-P
III-P
SI/1
SI/2
SI/3


2)
select komorka,ustalenia from analiza_1 a where a.koniec between '20040701'and '20040731'

komorka ustalenia
SI/1788138.9300
SI/246638.4900
SI/216218.4000
08.0000



3)
select p.komorka,isnull(sum(ustalenia),0)
from #plantemp p left join analiza_1 a on p.komorka=a.komorka
where a.koniec between '20040701'and '20040731'
group by p.komorka

komorka ustalenia (sum)

08.0000
SI/1788138.9300
SI/262856.8900




I need all rows from table 1 bat right and left join gives me the same results, WHY

View 3 Replies View Related

Left Join

Jan 9, 2007

There are two tables:
tblIndices:
IndexID, Name
1index1
2index2
3index3
.
.
.


tblBasketConstituents
ID, ParentIndexID, ChildIndexID, Weight
121 20
223 80
313 50
412 50

As you can see the ParentIndexID and ChildIndexID fields refer to tblIndices.IndexID
I would like a stored procedure as follows:
show all index names and show the wights for the indexID you passed.
This is what I have so far and it is not correct yet. Not sure what the syntax should be.


alter PROCEDURE [dbo].[uspBasketIndices_Get]

@IndexIDint

AS

select
i.IndexID,
i.[Name],
bc.Weight
from
tblIndices as i left join tblBasketConstituents as bc on i.IndexID = bc.ParentIndexID
and i.IndexID = @IndexID
order by
i.[Name]

View 1 Replies View Related

How Many 'LEFT JOIN' Is Too Many?

Feb 26, 2004

Any one know any facts and figures about maximum Left Joins allowed (or recommended) in one query?

I am running a MS SQL 2000 my database is full of relational data and most of my foreign keys (INT data type) are a Clustered Indexed, Usually I will only be pulling one record from collection of about a dozen tables, but the Database is expected to grow fast and become big.

Right now I have a Stored Proc that has eight(8) LEFT JOINs in it. My worry is that this query will kill me as the database approaches 50,000 records.

Lito

View 6 Replies View Related

Left Join

Mar 6, 2007

Hi all. My query works fine, it generates reports but not my expected result.

select d.fullname, p.nickname, p.birthdate, p.birthplace,
p.gender, p.civilstatus, p.religion, p.nationality, p. weight, p.height,
p.haircolor, p.eyecolor, p.complexion, p.bodybuilt, p.picture, p.dialectspoken,
d.mobilephone, d.prprovince,[Age] = dbo.F_AGE_IN_YEARS( birthdate, getdate() ),
c.name, c.address, c.telno, c.email, c.occupation, ed.year1, ed.year2, ed.degree, sch.schname
from hremployees as e
inner join psdatacenter as d on e.empdcno = d.dcno
inner join pspersonaldata as p on e.empdcno = p.dcno
left join hrappempcharrefs as c on e.empdcno = c.empdcno
left join hrappempeducs as ed on e.empdcno = ed.empdcno
left join hrsetschools as sch on ed.schoolcode = sch.schcode

the above query gives a 77 records

if i ran "select * from hremployees" generates 60 records

i think the error is in the left joining.
hrappempcharrefs, hrappempeducs and hrsetschools must be left joined to hremployees.

thanks
-Ron-

View 5 Replies View Related

Left Join Using Vb 9.0 And LINQ

Dec 2, 2007

Hi Guys,
I started working with linq and vb9.0 but i have a small problem i could feagure how to solve in c# but not in vb
I wanted to make left join or right join on vb 9.0 and linq is it possible or this is only c# feature ?
Waiting to hear from u guys,
Thanks
Softy

View 2 Replies View Related

Left Outer Join-please Help!

Jan 7, 2002

Hello!
I need to write a query using left outer join and I'm having trouble with it.
I have 2 tables:customer and cust_info.
I want to pull all records from customer table and cust_info table even if there is no related data in cust_info table.
But I need one condition in this query:only records from customer table where cus_type in ("A","B","C").
I don't need all other types ("D","E").

So my query looks like this:

select customer.cus_name,customer.cus_address,customer.cu s_type,cus_info.status
from customer
left outer join cus_info ON customer.sxdat_pk = cus_info.sxdat_pk
and cus_type in ("A","B","C")
AND cus_info.cus_table = 'CUSTOMER'

The result should be like this:

cus_name cus_address cus_type status
Amoco 457 bent A new
Bingo 47 lone oak C NULL
Sears 1020 Magic dr. B exist


But my query pulls records for customers with type "D" and "E" that I'm trying to exclude from result.


Please help.
Thanks,
lena

View 4 Replies View Related

LEFT JOIN Problem

Apr 18, 2008

Hello everybody!!!

I have to left join 2 tables. The first consists of columns:id, description, descr_num.
The second table: id, descr_num, value.

I need to extract description from table1 where descr_num is in the range , say, 1-10.

LEFT JOIN

extract value from table2 ,descr_num should be in the same range. in table2 some values from (1,10) and desc_num could be not present.
BUT i want this left join to be limited as i said.

Is there any solution to this prob. without creating temp tables. Or actually can i do such a join?
Thank you

View 2 Replies View Related

Left Join Table

Jul 18, 2006

Now I have a table with the table design as following :

table cst_EmpProfile
intEmpId nvcEmpName nvcEmpAddress intEmployeeType bitActiv
1 Peter Null Null true
2 Juli 1, xxxx 2 true
3 Sam Null Null False

table cst_EmpType
intEmpType nvcEmployeeType
1 Free Enginner
2 Manager
3 Operator

To join the table but MUST follow the condition as bitActiv = TRUE:
select emp.nvcEmpName, emp.nvcEmpAddress, ety. nvcEmployeeType from cst_EmpProfile emp left join cst_EmpType on emp.intEmployeeTypee = ety.intEmpType and emp.bitActiv = 1.

But, the sql statement doesnt output the my expected result.
Because the data row return must be 1st and 2nd row as it bitActiv = true.
So, how's I going achieve what i want. tq.

View 1 Replies View Related

Stumped - LEFT JOIN

Jan 10, 2007

Hi, I'm getting the error Syntax error (missing operator) in query expression 'dbPWork.id = dbPWorkWord.work_id LEFT JOIN words ON dbPWorkWord.word_id = words.id'." on the query below. Everything looks in place to me. Do you see anything that shouldn't work?

Query:

Code:

Code:

SELECT DISTINCT dbPWork.id, description_e as description, w_id , dateStart, dateEnd FROM dbPWork
LEFT JOIN dbPWorkW ON dbWork.id = dbPWorkW.work_id
LEFT JOIN words ON dbPWorkW.word_id = words.id



Everything works fine until I add the second LEFT JOIN statement. Any ideas? I'm stumped.

View 4 Replies View Related

Left Join Question

Sep 22, 2005

I have a left join that doesn't suit my request.

select * from A
left join B
on A.x=B.x

The problem is that for a specific record in A we can find 1 or more entries in B. What I want is to return only the 1st entry found on B.
thx

View 3 Replies View Related

Difference Between LEFT N RIGHT JOIN

Dec 6, 2005

Hi,
I have got a query for you guys. Can any one temme the difference between

"FROM Table_A LEFT JOIN Table_B" and "FROM Table_B RIGHT JOIN Table_A"



;)
Thanks,
Rahul Jha

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved