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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:31:52+00:00 2026-06-06T08:31:52+00:00

I am building a query to gather data from multiple tables. I want to

  • 0

I am building a query to gather data from multiple tables. I want to grab all of the item_ids from one table and then build the results by gathering other data from other tables based on that item_id. I could have sworn that this was possible; but, I can’t seem to get it to work. Here is an example of what I’m trying to do:

SELECT item_id AS mainID, 
 (SELECT anotherField 
  FROM anotherTABLE 
  WHERE item_id=mainID) 
FROM theMainTable;

Granted that is just an example. Essentially, I need to use the item_id from the main query inside the subquery. I could have sworn that I’d done this before, but I can’t remember how…

I’m trying to do this with just a query, not with any extra programming languages. I’d like to eventually set it as a stored procedure. Thanks or any assistance with this.

UPDATE

Looks like a join did work… Thanks for all the assistance.

Here is my final query just in case anyone else runs into something like this:

SELECT DISTINCT
    Q.item_id, Q.timestamp, Q.employee,
    QA.employeeNotes, Q2.itemDesc, Q2.itemExtraData
FROM 
    itemLog Q 
LEFT JOIN 
    itemComments QA ON Q.item_id = QA.item_id 
LEFT JOIN 
    itemLog Q2 ON Q.item_id = Q2.item_id AND Q2.type = 'begin' 
WHERE 
    Q.verb = 'itemStatus' 
    AND NOT (QA.employeeNotes IS NULL);
  • 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-06T08:31:54+00:00Added an answer on June 6, 2026 at 8:31 am
    SELECT a.item_id AS mainID, b.anotherField 
    FROM theMainTable a
        INNER JOIN anotherTABLE b ON a.item_id=b.item_id
    

    You should avoid using subqueries in select statements, because they will be computed for each returned row from the main table, whereas the inner join ensures proper optimization and tables paths.

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

Sidebar

Related Questions

I'm building a query that needs data from 5 tables. I've been told by
I'm thinking of building query from these 2 tables (on SQL Server 2008). I
I'm having trouble building a query. I can do what I want in 3
In sql 2005, instead of building a query from dateparts year, month and date,
I'm building a LINQ query dynamically based on user input, and I want to
I need some help building an Query. I have a table Orders with 3
need help building a query to replace fields on a table that match a
I need help with building SQL query. I have 4 tables: Sellers, Goods, Projects
i'm building a query on a search page based on user inputs, i then
I'm currently building a query like this: account.sales.method_needing_more_account_info(account) I want to be able determine

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.