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 481335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:59:02+00:00 2026-05-13T00:59:02+00:00

Hi I am fairly new to SQL – so be gentle with me! I

  • 0

Hi I am fairly new to SQL – so be gentle with me!

I basically have two tables that I am trying to join where the primary key in the first table is used multiple times in the second table (and forms the primary key in the second table along with another column)

It’s probably best if I provide an example:

Table 1 : TravelRecords

TravelEventID  EventType  RecordLocator  OfficeID    
 0001            F          ABC123         LDN  
 0002            F          ABC234         LDN  
 0003            T          BDF232         SOU  
 0004            F          DFD890         GLA  

Table 2 : TravelRecordRmks

TravelEventID  RemarkNo    Keyword       Text  
 0001            1           TVL          LOWCOST BOOKING  
 0001            2           TVL          CREDIT CARD USED  
 0001            3           PSG          COST CENTRE REQUIRED  
 0001            4           PSG          EMPLOYEE NUM REQUIRED
 0002            1           TVL          CREDIT CARD USED
 0002            2           AGT          BOOKED BY AGENT
 0002            3           AGT          CONFIRM WITH AIRLINE
 0002            4           TVL          LOWEST FARE CONFIRMED
 0002            5           TVL          NO CANCELLATION CHARGE
 0003            1           TVL          LOWCOST BOOKING
 0003            2           TVL          CARRIER : EASYJET
 0003            3           TVL          LOWEST FARE CONFIRMED
 0004            1           TVL          LOWCOST BOOKING
 0004            2           TVL          CREDIT CARD USED

For the second table the key is the combination of the TravelEventID and the RemarkNo which combined gives a unique ID.

Basically all I am trying to do is join the tables together and return the record locator for bookings that have a remark text line of LOWCOST BOOKING AND CREDIT CARD USED (so in the example above only ABC123 and DFD890 should be returned.

I’ve tried something along the lines of :

SELECT  TravelRecords.RecordLocator
FROM    TravelRecords INNER JOIN
        TravelRecordRmks ON TravelRecords.TravelEventID = TravelRecordRmks.TravelEventID db  
WHERE   (TravelRecordRmks.RemarkText = 'LOWCOST BOOKING') 
        and (TravelRecordRmks.RemarkText = 'CREDIT CARD USED')
ORDER BY dbo.vw_gTravelOrderEvent.RecordLocator

However – that returns nothing. This is probably really simple – but I can’t get it to return the required response when I am looking for the single TravelEventID to contain both Remark Text fields.

Any help much appreciated
Cheers

  • 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-05-13T00:59:02+00:00Added an answer on May 13, 2026 at 12:59 am

    The most readable way to check this is probably a double where exists, like:

    SELECT  tr.*
    FROM    TravelRecords tr
    WHERE EXISTS (
        SELECT * FROM TravelRecordRmks trr 
        WHERE trr.TravelEventID = tr.TravelEventID
        AND trr.RemarkText = 'LOWCOST BOOKING'
    )
    AND EXISTS (
        SELECT * FROM TravelRecordRmks trr 
        WHERE trr.TravelEventID = tr.TravelEventID
        AND trr.RemarkText = 'CREDIT CARD USED'
    )
    

    An alternative that might perform better, using an inner join subquery as a filter:

    SELECT  tr.*
    FROM    TravelRecords tr
    INNER JOIN (
            SELECT TravelEventID
            FROM TravelRecordRmks trr 
            WHERE RemarkText IN ('CREDIT CARD USED','LOWCOST BOOKING')
            GROUP BY TravelEventID
            HAVING COUNT(DISTINCT RemarkText) = 2
    ) filter 
    ON      filter.TravelEventID = tr.TravelEventID
    

    The HAVING COUNT(DISTINCT RemarkText) = 2 makes sure that both types of remarks are found.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm fairly new to SQL and was trying to write a procedure that would
I fairly new to JQuery and perhaps trying to achieve something that might be
I'm fairly new to SQL and I'm currently reworking a java program that another
I'm fairly new to asp.net and especially LINQ and SQL. Say I have a
I'm working with a SQL database (still fairly new to it) and have attempted
I'm fairly new to coding in T-SQL and have run into an issue I
I'm fairly new to SQL and I was trying to get a full list
I am trying to compare two tables, SQL Server, to verify some data. I
I am fairly new to Linq To SQL but trying to run what should
I'm fairly new to SQL, and i'm trying to make a query with simple

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.