Hello group-
I am having a problem where joined tables are returning too many rows.
Here is my scenario -
I am trying to create a temporary table from parts of three tables -
the important columns are:
a.id
a.tran_date
b.id
b.geo
c.holiday_date
c.geo
My query is like this
select a.col1, b.col1 from a
inner join b on a.id = b.id
inner join c on c.geo = b.geo
With the parameters that I have, I get 144 rows with just the join of
tables a & b.
However, when I add the join to table c, I get 720 rows - there are (of
course) 5 rows in table c where the geo is the same as the geo in table
b.
The reason for the join is that I need to know if a.tran_date =
c.holiday_date and holidays differ by GEO.
I don't want this added information. Thoughts on what I am doing wrong?
Please let me know if you need more information
Thanks-
Danielle 3 1358
Danielle wrote: Hello group- I am having a problem where joined tables are returning too many rows. Here is my scenario -
I am trying to create a temporary table from parts of three tables - the important columns are:
a.id a.tran_date
b.id b.geo
c.holiday_date c.geo
My query is like this
select a.col1, b.col1 from a inner join b on a.id = b.id inner join c on c.geo = b.geo
With the parameters that I have, I get 144 rows with just the join of tables a & b.
However, when I add the join to table c, I get 720 rows - there are (of course) 5 rows in table c where the geo is the same as the geo in table b.
The reason for the join is that I need to know if a.tran_date = c.holiday_date and holidays differ by GEO.
I don't want this added information. Thoughts on what I am doing wrong?
Please let me know if you need more information
Thanks- Danielle
Please post DDL and sample data, otherwise any answers you get will
just be guesswork. See: http://www.aspfaq.com/etiquette.asp?id=5006
My guess is that you can use EXISTS or NOT EXISTS instead of a JOIN to
C. Your spec is too vague for me to be sure though.
--
David Portas
SQL Server MVP
--
Hi Danielle
I am not sure what you mean by holidays differ by GEO!
Maybe you are wanting to extend the join clause to eliminate rows where the
dates don't match?
e.g.
select a.col1, b.col1
from a
join b on a.id = b.id
join c on c.geo = b.geo AND a.tran_date = c.holiday_date
Otherwise please post DDL, Sample data and expected output as David
reqested.
John
"Danielle" <wx****@aol.com > wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com... Hello group- I am having a problem where joined tables are returning too many rows. Here is my scenario -
I am trying to create a temporary table from parts of three tables - the important columns are:
a.id a.tran_date
b.id b.geo
c.holiday_date c.geo
My query is like this
select a.col1, b.col1 from a inner join b on a.id = b.id inner join c on c.geo = b.geo
With the parameters that I have, I get 144 rows with just the join of tables a & b.
However, when I add the join to table c, I get 720 rows - there are (of course) 5 rows in table c where the geo is the same as the geo in table b.
The reason for the join is that I need to know if a.tran_date = c.holiday_date and holidays differ by GEO.
I don't want this added information. Thoughts on what I am doing wrong?
Please let me know if you need more information
Thanks- Danielle
Hello Danielle
"The reason for the join is that I need to know if a.tran_date =
c.holiday_date and holidays differ by GEO."
Im not sure what you want since this is a bit cryptic but is this code
similar to what you need?
select distinct
a.col1,
b.col1
from a
inner join b on b.id = a.id
inner join c on c.holiday_date= a.tran_date
where b.geo<>c.geo;
Also, you showed some concern about the number of rows returned. Use
"distinct" keyword to get unique records and a more concise number of
rows.
best regards This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 solve my problem.
I'll turn to MySQL doc after getting through this pressing project.
Thanks a lot Roger!
Babale
-----Urspr=FCngliche Nachricht-----
|
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 SUBSTRING(ProductName,
1, CHARINDEX('(', ProductName)-2).
I can get this result, but I had to use several views (totally
inefficient). I think this can be done in one efficient/fast query,
but I can't think of one.
In the case that one query is not...
|
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, Employees.LastName, TerritoryID,
Employees.EmployeeID,
RegionID, ProductID
from Employees
|
by: ColdCanuck |
last post by:
Help!
I'm trying to understand the new ANSI join syntax (after many years of
coding using the old style). I am now working with an application that only
understands ANSI syntax so I am struggling.
My first (old style syntax) SQL statement below produces 60 rows:
SELECT A1.CONTACTID, A1.LASTNAME, A1.FIRSTNAME, A1.ACCOUNT,
A6.CITY, A6.STATE, A1.WORKPHONE, A1.FAX, A1.EMAIL
|
by: google |
last post by:
I have a database with four table. In one of the tables, I use about
five lookup fields to get populate their dropdown list. I have read
that lookup fields are really bad and may cause problems that are hard
to find. The main problem I am having right now is that I have a report
that is sorted by one of these lookup fields and it only displays the
record's ID number. When I add the source table to the query it makes
several records...
| |
by: Terry Olsen |
last post by:
I need to get information from 3 tables in an MDB file.
I need all the columns in the first table.
I need 2 columns in the 2nd table where it's primary key matches a
column in the first table.
I need several columns in the 3rd table where it's primary key matches a
column in the 2nd table.
I tried this:
|
by: Chuck36963 |
last post by:
Hi all,
I've been working on a listing problem and I can't figure out how to work it out. I have looked far and wide on the web to find answers, but I'd like other peoples input on my project in the whole. I really need MySQL wizz to give me a hand (and maybe refer me to books to get me to the wizz level myself).
First off, english is a second language to me and sometimes my sentences might be a little awkward. Please forgive me. Mon...
|
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 because of the TOP 9. Any Suggestions???
(SELECT TOP 9 trans.vchTrustee, trans.vchCaseNumber, Trans.TotalReceipts + SUM(a.mnyBalanceAmount) As Top9Total
FROM tblCase c1
LEFT JOIN tblAsset a ON c1.intCaseID = a.intCaseID
LEFT JOIN
|
by: muld |
last post by:
I've inherited a database system designed to calculate sickness absence statistics. There is a main table with an employee ID which also holds the number of days worked by that person in a year . There is then a table which records absences for each employee, it records the date of the absence etc and also holds the number of days absent . Each time the employee is absent they will have an entry in this table linked by . I have created a query...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |