Solved

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

Posted on 2004-10-12
5
492 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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.

825 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