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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:46:57+00:00 2026-05-21T16:46:57+00:00

Table User contains the fields id, name, fruit, veggies, meat. Table FruitType contains the

  • 0

Table User contains the fields id, name, fruit, veggies, meat.
Table FruitType contains the fields id, type, healthy, user.
Let’s presume the table User looks like this:

1, Marvin, Apple, Carrot, Pork
2, Zorlax, Blueberry, Lettuce, Lamb

.. while the FruitType table looks like this:

1, fruit, yes, 1
2, veggies, yes, 2

What I would like is to be able to JOIN them, and search for a value in Users, in a specific field, depending on the VALUE from the “type” field in FruitType. For example, I would like to be able to do this:

SELECT User.'type' FROM User 

LEFT JOIN FruitType ft ON (ft.user = User.id) etc.. conditions and so on...

Basically, I want the ‘type’ part to take the value of the ‘type’ field in the FruitType table. Something like a field variable, in essence.

I hope I’m being clear enough. Here is a real example I’m working on right now, in case this seems too confusing, although the real one might do even more damage:

  IF (trigger_by_date IS NOT NULL,
  date_add(books.trigger_by_date, INTERVAL trigger_by_date_add DAY),
  date_add(trigger_step_created_at, INTERVAL trigger_by_step_add DAY))
  as deadline

In this case, trigger_by_date is the variable. If it’s not null, simply use its value as the field identifier.

Edit:

For clarity’s sake: there is no “type” column in User. The “type” in the example query should be replaced by the actual value of type in the FruitType table. So if a condition yielded the result FruitType.type = fruit, I want the query to SELECT User.fruit. If a condition gave FruitType.type = veggies, I want the query to SELECT User.veggies. I hope it is clearer now. I basically want the field I am selecting to depend on the type in FruitType.

  • 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-21T16:46:58+00:00Added an answer on May 21, 2026 at 4:46 pm

    The solution was rewriting the query with a couple of advanced subqueries.

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

Sidebar

Related Questions

I have a table in a database that contains two fields id name I
I have a table (user) that contains user information. I have another table (userview)
I've got a User table with a bitmask that contains the user's roles. The
I currently have a user's table which contains a one-to-one relationship for Youtube OAuth
table user: |id|name|employee_priority_id|user_priority_id| table priority: |id|name| As you can see, there are two foreign
My User table I want to map to aspnet_Users: <class name=User table=`User`> <id name=ID
When designing user table what would be the must have fields from the security/user
I am using two tables. User table contains the firstname and lastname field and
im developing a cms. the Table clients contains many fields and one of them
I am working with a legacy database schema that looks like this: product_table table

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.