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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:19:21+00:00 2026-05-12T12:19:21+00:00

I’m a little new to SQL and have come across the following problem. I

  • 0

I’m a little new to SQL and have come across the following problem.

I have a table with company details on it which is joined to a contact table by an enqID.

Within the contact table, there are 4 different types of contacts which may or may not have an entry. These are differentiated by a ctcTypID (1 – 4)

I would like to produce a query that has all of the company records on it plus a contact name for each of the 4 different types of contact, all on one row.

I thought I could do this by using subqueries for each of the different contacts but I can’t seem to get it to work as I don’t know how to write a subquery select clause that references it’s parent select clause (if you see what I mean!)

Is this even possible? As I’ve mentioned, I’m pretty new to SQL so please try not to mock too much!

Thanks,

Steve

  • 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-12T12:19:21+00:00Added an answer on May 12, 2026 at 12:19 pm

    Something like (assuming you’re using SQL Server 2005 and up – unfortunately, you didn’t mention that in your original post):

    SELECT 
       c.CompanyName,
       c1.ctcTypID, c1.ContactName,
       c2.ctcTypID, c2.ContactName,
       c3.ctcTypID, c3.ContactName,
       c4.ctcTypID, c4.ContactName
    FROM
       CompanyTable c
    LEFT OUTER JOIN
       ContactTable c1 ON c.enqID = c1.enqID AND c1.ctcTypID = 1
    LEFT OUTER JOIN
       ContactTable c2 ON c.enqID = c2.enqID AND c2.ctcTypID = 2
    LEFT OUTER JOIN
       ContactTable c3 ON c.enqID = c3.enqID AND c3.ctcTypID = 3
    LEFT OUTER JOIN
       ContactTable c4 ON c.enqID = c4.enqID AND c4.ctcTypID = 4
    

    You need to use LEFT OUTER JOINs since there might not be a match, and by doing this, your query will not be awfully fast in terms of performance – but it should hopefully work.

    Marc

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.