[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

SQL syntax producing duplicate results

I have an SQL query that is producing overstated records.  I have 2 tables, History_1 and History_2 tables.  History 1 has multiple data rows matching Call_ID which is creating overstated results.  What I need to happen is only to match against 1 of the mutiple data matching records to produce accurate results.  I have attached the SQL Syntax.  Thanks.
Use Dialer

Select
Facility_Name As "Facility",
History_1.Client As "Client",
Count(History_1.Client) As "Count"

From
History_1,
History_1,
LU_Clients

Where
History_1.Call_ID = History_2.Call_ID and
History_1.Client = LU_Clients.Facility_ID

Group By
History_1.Client,
Facility_Name

Open in new window

0
OB1Canobie
Asked:
OB1Canobie
  • 3
  • 3
1 Solution
 
tigin44Commented:
try this
Use Dialer

Select
Facility_Name As "Facility",
History_1.Client As "Client",
Count(History_1.Client) As "Count"
From History_1
		INNER JOIN History_1 ON History_1.Call_ID = History_2.Call_ID  
		INNER JOIN LU_Clients ON History_1.Client = LU_Clients.Facility_ID
Group By
History_1.Client,
Facility_Name

Open in new window

0
 
tigin44Commented:
I missed a point in the above post... try this...
Use Dialer

Select
Facility_Name As "Facility",
History_1.Client As "Client",
Count(History_1.Client) As "Count"
From History_1
		INNER JOIN History_2 ON History_1.Call_ID = History_2.Call_ID  
		INNER JOIN LU_Clients ON History_1.Client = LU_Clients.Facility_ID
Group By
History_1.Client,
Facility_Name

Open in new window

0
 
HainKurtSr. System AnalystCommented:
is it a type? you used History_1 twice in from part without an alias

try this, and add aliases to the all columns first:

...
From
      History_1 h1,
      History_1 h2,
      LU_Clients lu
Where
...
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
OB1CanobieAuthor Commented:
Thanks.  This fixed the replication.
0
 
HainKurtSr. System AnalystCommented:
tigin44, whats the difference between the one accepted and original query?
they should give the same result!...
0
 
tigin44Commented:
the user has two tables named History_1 and History_2... I used them...
0
 
HainKurtSr. System AnalystCommented:
oooh, same observation as 26149492 ;)
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now