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

  • Home
  • SEARCH
  • 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 8144127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:17:18+00:00 2026-06-06T13:17:18+00:00

I am trying to make an SQL statement that takes eight different numbers and

  • 0

I am trying to make an SQL statement that takes eight different numbers and searches eight different tables from one database for the corresponding value. I keep getting invalid syntax, but I can’t figure out why. Here is my code:

SELECT cable_length.ID, drawing.ID, optional.ID, output_type.ID, pressure_range.ID, pressure_type.ID, series.ID, termination.ID 
FROM
(
    SELECT value AS cable_length FROM A1 WHERE A1.id = %s
    JOIN SELECT value AS drawing FROM A2 WHERE A2.id = %s,
    JOIN SELECT value AS optional FROM A3 WHERE A3.id = %s,
    JOIN SELECT value AS output_type FROM A4 WHERE A4.id = %s,
    JOIN SELECT value AS pressure_range FROM A5 WHERE A5.id = %s,
    JOIN SELECT value AS pressure_type FROM A6 WHERE A6.id = %s,
    JOIN SELECT value AS series FROM A7 WHERE A7.id = %s, 
    JOIN SELECT value AS termination FROM A8 WHERE A8.id = %s
);

The %s will be changed to numbers only. The column name in each table is “ID” and “Value”. I want to search by “ID” and return “Value”. The table names are cable_length, etc. Any help is greatly appreciated.

  • 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-06T13:17:21+00:00Added an answer on June 6, 2026 at 1:17 pm

    If you know that all 8 values are present, you can join like this:

    SELECT  A1.value as cable_length
      , A2.value as drawing
      , A3.value as optional
      , A4.value as output_type
      , A5.value as pressure_range
      , A6.value as pressure_type
      , A7.value as series
      , A7.value as termination
    FROM A1, A2, A3, A4, A5, A6, A7, A8
    WHERE A1.ID = %s
      AND A2.ID = %s
      AND A3.ID = %s
      AND A4.ID = %s
      AND A5.ID = %s
      AND A6.ID = %s
      AND A7.ID = %s
      AND A8.ID = %s
    

    If you do not know this, but you’re guaranteed that the first value is present, then your query has to get uglier because you need left joins.

    SELECT  A1.value as cable_length
      , A2.value as drawing
      , A3.value as optional
      , A4.value as output_type
      , A5.value as pressure_range
      , A6.value as pressure_type
      , A7.value as series
      , A7.value as termination
    FROM A1
      LEFT JOIN A2
        ON A2.ID = %s
      LEFT JOIN A3
        ON A3.ID = %s
      LEFT JOIN A4
        ON A4.ID = %s
      LEFT JOIN A5
        ON A5.ID = %s
      LEFT JOIN A6
        ON A6.ID = %s
      LEFT JOIN A7
        ON A7.ID = %s
      LEFT JOIN A8
        ON A8.ID = %s
    WHERE A1.ID = %s
    

    If none of the values are guaranteed present, the hack is to have a subquery that is a UNION ALL of 8 queries that return the 8 columns with only one filled, then select the MAX of each column as that column name.

    This is an awful trick that I’ve used in the past to avoid performance problems with many left joins that only occasionally join.

    Incidentally 8 tables named A1..A8 suggests that you need someone who is experienced with databases to look over your design and give you a much better layout.

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

Sidebar

Related Questions

I'm trying to make a select statement that joins results from three in-line table
I'm trying to make a SQL statement that gives me the top X records
I am trying to make an SQL Function that returns a nvarchar(MAX) string. The
I am trying to make a query to an SQL database and I can't
I'm trying to write a stored procedure in SQL that will : Make a
I'm trying to write an SQL Statement that needs to loop through a list
I am trying to make a LINQ statement where the where clause comes from
How do you make an SQL statement that returns results modified by a subquery,
I'm trying to make this ASP/SQL statement to work but I keep getting ORA-01036:
I am trying to come up with a DB2 SQL statement that does the

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.