Solved

Inner join select results in double query return, all rows are double ... !!!

Posted on 2004-10-12
5
496 Views
Last Modified: 2008-02-01
When this query is executed it returns all rows two times right after each other... why ?

select fromdate as startDate,toDate as endDate,jc.recid as vacation_id,'' as text,ja.description as type,1 as accepted,ltrim(emplID) as employee_initials from AXSQL.AXDBTEST.DBO.JMGABSENCECALENDAR as jc inner join AXSQL.AXDBTEST.DBO.JMGIPCACTIVITY as ja on ja.JOBID=jc.JOBID  where ltrim(EMPLID)='CHK'
0
Comment
Question by:mSchmidt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:praveen_ms
ID: 12285380
Looks like you have duplicate records try running this

select DISTINCT fromdate as startDate,
toDate as endDate,
jc.recid as vacation_id,
'' as text,
ja.description as type,
1 as accepted,
ltrim(emplID) as employee_initials
from AXSQL.AXDBTEST.DBO.JMGABSENCECALENDAR as jc
inner join AXSQL.AXDBTEST.DBO.JMGIPCACTIVITY as ja on ja.JOBID=jc.JOBID
where ltrim(EMPLID)='CHK'
0
 
LVL 2

Assisted Solution

by:praveen_ms
praveen_ms earned 250 total points
ID: 12285400
If you are expecting only one row to be returned with out distinct just make sure that you don't have two job ID's in any of these tables to verify that

you can run

select count(ja.JOBID), ja.JOBID
from AXSQL.AXDBTEST.DBO.JMGIPCACTIVITY as ja
GROUP BY ja.JOBID
HAVING count(ja.JOBID)>1

and similary repeat on the other table. If you see any records with count more than 1 then this job id should be duplicated.
0
 
LVL 6

Accepted Solution

by:
etmendz earned 250 total points
ID: 12285402
Maybe the relationship is one-to-many and there are already two activity entries per calendar entry? Better yet, check your activity table. It may have double entries for all activities in the first place.
0
 
LVL 6

Expert Comment

by:etmendz
ID: 12285412
In fact, maybe your calendar contains duplicates :-)

Have fun...
0
 

Author Comment

by:mSchmidt
ID: 12285700
It did have double entries, dah, chose to use Distinct to only get one result.. thanks guys
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question