Hey All,
I really need some help here!
I currently have 3 databases that I am writing a script for to extract data. I need to join these databases together to get one extract, but I have a whole bunch of data that I need and from different tables in the database. Therefore I have left outer joins to join up tables in there.
SQL won't let me join the databases if I have left outer joins as well, but I have only been trying a Union.
Any suggestions are welcome :)
7 1589
more specifics please.
what have you tryed so far? what do you mean --> "SQL won't let me join the databases if I have left outer joins"
what kind of errors are you getting?
present some examples.
Sorry - I'm only learning SQL at the moment so I might not have it right, but this is an example:
use databasea
go
select
employee.employeecode,
employee.firstnames,
employee.lastname,
employee.locationcode,
location.description,
employee.positioncode,
position.description
from employee
left outer join location location on
(employee.locationcode = location.locationcode)
left outer join position position on
(employee.positioncode = position.positioncode)
where employee.terminationdate is NULL
I have written a script to join the databases using a union before, but if I try this and use a left outer join it doesn't work:
select
ea.employeecode,
ea.firstnames,
ea.lastname,
ea.departmentcode,
ea.locationcode,
ea.Xdatabase
from databasea.dbo.Employee ea
where ea.terminationdate is NULL
AND ea.EmployeeCode NOT LIKE '[_]%'
union
select
eb.employeecode,
eb.firstnames,
eb.lastname,
eb.departmentcode,
eb.locationcode,
eb.Xdatabase
from databaseb.dbo.Employee eb
where eb.terminationdate is NULL
AND eb.EmployeeCode NOT LIKE '[-]%'
Please excuse my very basic scripts, I'm just a beginner :)
the administrators are going to ask you to put your code in code tags when you post. It's the "#" sign in the messagebox menu bar.
So, I'm still confused here. you are showing two queries. One with Left Joins and One with a Union. Which one exactly is failing? and again, what errors are you getting?
Sorry - so I have figured out how to join the databases now, but the join isn't working on the third database although it isn't failing as the employees are there, it just has NULL in the cell. I have just written the below basic formula:
use databasea
go
select
employee.employeecode,
employee.firstnames,
employee.lastname,
employee.locationcode,
location.description,
employee.positioncode,
position.description
From
(
Select
ea.employeecode,
ea.firstnames,
ea.lastname,
ea.locationcode,
ea.positioncode,
ea.terminationdate
from databasea.dbo.employee ea
union
select
eb.employeecode,
eb.firstnames,
eb.lastname,
eb.locationcode,
eb.positioncode,
eb.terminationdate
from databaseb.dbo.employee eb
union
select
ec.employeecode,
ec.firstnames,
ec.lastname,
ec.locationcode,
ec.positioncode,
ec.terminationdate
from databasec.dbo.employee ec
)
employee
left outer join location location on
(employee.locationcode = location.locationcode)
left outer join position position on
(employee.positioncode = position.positioncode)
where employee.terminationdate is NULL
order by employee.employeecode
The above were two different scripts, I was just trying to show what I wanted to be joined and then also how I have joined the databases with a union before.
The above script should make more sense.
Thanks
Sorry I mean't the last reply (#3) was two different scripts.
Ahhh... I have just realised that my databases are not exactly the same and therefore there are NULL's because the fields aren't set up in some of the databases.
Is this the best way to join them?
So are you saying your queries are working now? If so then you are fine with the way you have them constructed.
the only thing I see is that I don't believe you need to repeat your table name
this is yours: - left outer join location location on
-
you only need this: - left outer join location on
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dam |
last post by:
Using SqlServer :
Query 1 :
SELECT def.lID as IdDefinition,
TDC_AUneValeur.VALEURDERETOUR as ValeurDeRetour
FROM serveur.Data_tblDEFINITIONTABLEDECODES def,...
|
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"...
|
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"...
|
by: Ian Boyd |
last post by:
i know nothing about DB2, but i'm sure this must be possible.
i'm trying to get a client to create a view (which it turns out is called a
"Logical" in DB2). The query needs a LEFT OUTER JOIN, but...
|
by: Dev |
last post by:
Hello all,
I need to do a left out join where a.field1 ilike %b.field2%
But I can not figure out the exact syntax to using the ilike in the join?
----------
|
by: Brian Parker |
last post by:
I'm new to ms-sqlserver ( 2000 ) and need to get an OUTER JOIN working
on a three table query.
Assumptions:
-- I have events in the Event table.
-- Each event CAN have one Transaction, but it's...
|
by: media.opslag |
last post by:
Hi,
How can i get this to work in access / jet sql ??? Someone??
SELECT
tbl1.,
tbl2.
FROM tbl1
left outer join tbl2 on
|
by: ibadba |
last post by:
Hello all, today I think I'm stupid, can anyone confirm??
I have a query on multinode DB2 ( v8.2 Aix ), as follows:
select a.col1,b.col1,c.col1
from
table1 a
left outer join
table2 b
on
|
by: Mickey001 |
last post by:
Greetings all,
I need some help in writing and understanding a sql query for the following:
Here is a simplified scenario:
2 Tables:
First Table Name
=============
|
by: nico3334 |
last post by:
I currently have a query that Joins 2 Tables (Table1 and Table2) using
LEFT OUTER JOIN. Here is an example of that query:
SELECT a.supply,
a.state,
b.cost
FROM Table1 a
LEFT...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |