Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
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…
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

867 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now