Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8316683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:24:58+00:00 2026-06-08T21:24:58+00:00

I have two sqlserver 2005 tables: Task table and Travel table. I am trying

  • 0

I have two sqlserver 2005 tables: Task table and Travel table.

I am trying to write a query that selects all records from the Task table for a specific Empid, and if the Task is travel, also get the mileage value from another table.

I expect only one row to be selected, but all rows in the Task table are returned.

The query I am using is

Select Tasklog.TaskLogPkey, Tasklog.Empid , Tasklog.Task, TravelLog.Mileage from 
Tasklog
left join TravelLog
on   
   TaskLog.EmpId = 12 and TaskLog.Task ='Travel'   and 
   TaskLog.TaskLogPkey = TravelLog.TaskLogPkey

But it makes no difference if I don’t include

  -- TaskLog.EmpId = 12 and TaskLog.Task ='Travel'   and 

What am I doing wrong?

Clearly the following doesn’t work:

Select Tasklog.TaskLogPkey, Tasklog.Empid , Tasklog.Task, TravelLog.Mileage from 
Tasklog where   TaskLog.EmpId = 12 and TaskLog.Task ='Travel' 
left join TravelLog
on   
   TaskLog.TaskLogPkey = TravelLog.TaskLogPkey

These are the tables I am using:

Create table TaskLog(
TaskLogPkey int not null,
Empid  int,
Task varchar(30)
)

Insert Tasklog values(1,12,'Sales')
Insert Tasklog values(2,4,'Travel')
Insert Tasklog values(3,63,'Meeting')
Insert Tasklog values(4,12,'Travel')
Insert Tasklog values(5,12,'Email')
Insert Tasklog values(6,4,'Travel')
Insert Tasklog values(7,63,'Meeting')
Insert Tasklog values(8,12,'PhoneCall')


Create table TravelLog(
TaskLogPkey int not null,
Mileage  int
)

Insert TravelLog values(2,45)
Insert TravelLog values(4,25)
Insert TravelLog values(6,18)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:24:58+00:00Added an answer on June 8, 2026 at 9:24 pm

    When you perform an Outer join ( a left join is a Left Outer Join), you get all the records in the inner side of that join, — no matter what predicates (filters) you specify on the other outer side in the join conditions.
    To filter the other side you need to add a Where clause.

    Select t.TaskLogPkey, t.Empid , t.Task, v.Mileage 
    From Tasklog t 
        Left Join TravelLog v 
             On t.TaskLogPkey = v.TaskLogPkey 
    Where t.Task ='Travel' 
        And t.EmpId = 12 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables that I am trying to join in a query, but
Good Afternoon All, I have two tables in my SQL Server 2005 DB, Main
I have got two tables in SQL Server 2005: USER Table: information about user
In SQL Server 2005/2008, is there some significance to tables that have two leading
we have two related tables(inventory and inventoryLocalization) on Sql Server 2005. the first table's
We have two tables in a SQL Server 2005 database, A and B.There is
I'm using SQL-SERVER 2005. I have two tables as you can see on diagram,
I'm using SQL-Server 2005. I have two tables Users and Payments which has a
I have two tables, both with the same columns. The first table contains original
Assume that I have two parent tables: Company and Contact . Assume that both

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.