Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

744 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

13 Experts available now in Live!

Get 1:1 Help Now