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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:13:21+00:00 2026-06-14T00:13:21+00:00

The below code is a result of a query i have created, it all

  • 0

The below code is a result of a query i have created, it all works fine apart from one thing. I have Material ID’s for material names:

1 = bath
2 = sink
3 = toilet

The below works but displays sink for every material

Select cu.FName + '  ' + cu.SName as 'Name', 
cu.Address1 + ', ' + cu.Address2 + ', ' + cu.Address3 as 'Dispatch Address', 
cu.PostCode, 
co.DateOrdered,
co.Material1,
ma.MaterialName,
co.material2, 
ma.MaterialName, 
ma.Price as 'Item Price' 
from Customers cu 
left join CustomerOrder co on co.CustomerID = cu.CustomerID
left join ItemOrder it on it.OrderID = co.OrderID 
left join Materials ma on ma.MaterialID = co.Material1 
or co.material2 = ma.MaterialItemID or co.material3 = ma.MaterialItemID

it displays as follows (just the materials are listed to stop confusion)

Material1 | MaterialName | Material2 | Material2Name | Material3 | Material3Name
    1          Sink            2           Sink           3             Sink

Can anybody help with this?

  • 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-14T00:13:22+00:00Added an answer on June 14, 2026 at 12:13 am

    There are a few ways that you can do this including using JOIN on the materials table multiple times to get the result:

    Select cu.FName + '  ' + cu.SName as 'Name', 
        cu.Address1 + ', ' + cu.Address2 + ', ' + cu.Address3 as 'Dispatch Address', 
        cu.PostCode, 
        co.DateOrdered,
        co.Material1,
        ma1.MaterialName Material1Name,
        co.material2, 
        ma2.MaterialName Material2Name, 
        ma1.Price as 'Item Price',
        co.material3, 
        ma3.MaterialName  Material3Name
    from Customers cu 
    left join CustomerOrder co 
        on co.CustomerID = cu.CustomerID
    left join ItemOrder it 
        on it.OrderID = co.OrderID 
    left join Materials ma1 
        on ma1.MaterialID = co.Material1 
    left join Materials ma2 
        on co.material2 = ma2.MaterialItemID
    left join Materials ma3 
        on co.material3 = ma3.MaterialItemID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I use below code query database, I cannot get any result, but I
I have created a stored procedure which works perfectly fine when I execute it
Description: the query actually run have 4 results returned,as can be see from below,
I have the below query and it works perfect , no issues SELECT description
I have code which is essentially $query = mysql_query('SELECT `foo` FROM `Bar` WHERE id=1',
Why does the code below result in org.datanucleus.exceptions.NucleusUserException: Object Manager has been closed? The
I understand that the code below would result segmentation fault because at the cstr
I ended up with this horrible code below, I can't get a better result
I am using SQL Developer to debug code like below, the output result will
I am using the script code below to get results from my database based

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.