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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:14:43+00:00 2026-05-25T13:14:43+00:00

I hate to submit a new question, but everyone else has some slight thing

  • 0

I hate to submit a new question, but everyone else has some slight thing that is different enough to make this one seem necessary to ask.

Users are to type in a vendor name, and then see all the “kinds” of things they have bought from that company, in a list, sorted by the lowest-inventory-on-hand.

Summary:
I have three tables.
There are more fields than these, but these are the relevant ones (as far as I can tell).

stuff_table
stuff_vendor_name *(search this field with $user_input, but only one result per lookup_type)*
lookup_type

lookup_table
lookup_type
lookup_quantity (order by this)
category_type

category_table
category_type
category_location (check if this field == $this_location, which is already assigned)

Wordier Explanation:
The users are searching for a value that is contained only in the stuff_table — distinct stuff_vendor_name values for each lookup_type. Each item can be bought from multiple sources, the idea is to see if any vendor has ever sold even one of any type of item before.

But the results need to be ORDER BY the lookup_quantity, in the lookup_table.

And importantly, I have to check to see if they are searching the correct location for these categories, located in the category_table in the category_location field.

How do I efficiently make this query?
Above, I mentioned the variables that I have:
$user_input (the value we are searching for distinct matches in the stuff_vendor_name field) and $current_location.

To understand the relationship of these tables, I will use an example.
The stuff_table would have dozens of entries with dozens of vendors, but have a lookup_type of, say, “watermelon,” “apple,” or “cherry.”
The lookup_table would give the category_type of “Jellybean.” One category type can have multiple lookup_types. But each lookup_type has exactly one category_type.

  • 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-25T13:14:43+00:00Added an answer on May 25, 2026 at 1:14 pm

    I made a nested query instead.

    The final code looks like this:

    $query_row=mysql_query(
    "SELECT DISTINCT * FROM table_a WHERE 
    field_1 IN (SELECT field_1 FROM table_b WHERE field_2 = $field_2) 
    AND field_3 IN (SELECT field_3 FROM table_c WHERE field_4 = $field_4)
    ORDER BY field_5 DESC
    ");
    

    This was incredibly simple. I just didn’t know you could do a nested query like that.

    I read it was “bad form” because it makes some kind of search optimization not as good as it could be, so be careful using nested select statements.

    However for me, it seemed to actually be significantly faster.

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

Sidebar

Related Questions

I hate to ask such a general question, but the following code is a
I hate that I'm doing this but I've just started working with Javascript classes
I hate hate IE! Now that I've ranted, I could really do with some
I hate giving out my code like this but I'm getting some errors about
I hate to ask such a dumb question, but I'm just starting out, so
I hate to give the question this heading but I actually don't know whats
I hate case sensitivity in databases, but I'm developing for a client who uses
I hate Physics, but I love software development. When I go back to school
I hate to have to ask, but I'm pretty stuck here. I need to
I hate the JavaBeans pattern with a passion that burns like the fire of

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.