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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:25:05+00:00 2026-05-26T21:25:05+00:00

This is pretty much just a simple join statemnet I believe. I’ve not worked

  • 0

This is pretty much just a simple join statemnet I believe. I’ve not worked with SQL much lately and seem to have forgotten how to do this. What I have is an item with few columns in it that reference another table for the name of that field. Like this:

id, name, effect1, effect2, effect3, effect4

The effects reference another table that only has a, id, and name columns. What I’m trying to do is run a query that will pull those names for each of those effects.

Something like:

SELECT i.name,e.name AS effect1, e.name AS effect2, e.name AS effect3, 
       e.name AS effect4 
FROM item i, effects e 
WHERE i.effect1 = e.name 
 AND i.effect2 = e.name 
 AND i.effect3 = e.name 
 AND i.effect4 = e.name

So, say I have an item that has values like this:

Toast, 1, 2, 3, 4

and the effects are:

1, burned
2, untoasted
3, wet
4, texas 

I want it to display toast, burned, untoasted, wet, texas

And ideas?

update:

Table items
id, name, weight, value, effect1,effect2,effect3,effect4

Table effects
id, name

In the effect1,… columns are the id number for the corresponding item in the effect table. A lot ofitems are going to share the same effects, so instead of inflating this already large database with redundant data, I decided to use a join to save space. At the same time I managed how to forget to do it, lol

Update #2
This is the effect I’m going for, but on more than one of the effect columns

SELECT i.name, i.weight,i.value, e.name AS 'effect 1' 
FROM ingredients i JOIN effects e ON effects._id=i.effect1

This works for 1, but if I try to do multiple it just crashes. Any ideas how I can get that effect for all 4 effects?

  • 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-26T21:25:05+00:00Added an answer on May 26, 2026 at 9:25 pm

    You need a distinct join for every column:

    SELECT i.name
         , i.weight
         , i.value
         , e1.name AS effect1
         , e2.name AS effect2
         , e3.name AS effect3
         , e4.name AS effect4
    FROM   ingredients i 
    LEFT   JOIN effects e1 ON e1.id = i.effect1
    LEFT   JOIN effects e2 ON e2.id = i.effect2
    LEFT   JOIN effects e3 ON e3.id = i.effect3
    LEFT   JOIN effects e4 ON e4.id = i.effect4;
    

    LEFT JOIN still keeps the ingredient if any of the effects is missing.
    The query depends on effects.id being unique.

    You can achieve the same with correlated subqueries:

    SELECT i.name
         , i.weight
         , i.value
         , (SELECT e.name FROM effects e WHERE e.id = i.effect1) AS effect1
         , (SELECT e.name FROM effects e WHERE e.id = i.effect2) AS effect2
         , (SELECT e.name FROM effects e WHERE e.id = i.effect3) AS effect3
         , (SELECT e.name FROM effects e WHERE e.id = i.effect4) AS effect4
    FROM   ingredients i;
    

    Database design

    If every ingredient has 4 effects your db design is fine. If the number of effects vary or you have additional information per effect, you might consider an n:m relationship between ingredients and effects, implemented by an additional table. (Replacing the four effect* columns.) Could look like this:

    CREATE TABLE ingredients_effects (
      ingredients_id integer REFERENCES ingredients(id)
    , effects_id     integer REFERENCES effects(id)
      -- additional data like quantity or notes?
    , PRIMARY KEY (ingredients_id, effects_id)
    );
    

    More details in the fine manual.

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

Sidebar

Related Questions

I have a simple HTTP server running that pretty much just serves an MP3
This is pretty much the same problem i have, except with very different code:
Pretty much the same as this question. But I can't seem to get this
I have a simple question for you (i hope) :) I have pretty much
This pretty much has me defeated. On XP and earlier versions of Windows you
this pretty much is the thing. When in tinymce I press anything that is
This is pretty much a duplicate question but instead of using Castle Dynamic Proxy
I think this is pretty much the simplest case for mapping a Map (that
I'm having some weird issues with Xcode, and this is pretty much impossible to
This is a pretty-much theoretical question, but.. How much of an operating system could

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.