?
Solved

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

Posted on 2004-10-12
5
Medium Priority
?
501 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 1000 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 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Suggested Courses

752 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