[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.8

SQL statement challenge - easy or difficult?

Asked by ibell in MySQL Server

Tags: mysql, category, database, sql

I'm coming over from Oracle to MySQL and under Oracle we could do things like: SELECT * from x where y IN (select * from z) ..  I am not sure this can be done with MySQL so I'm posing a scenario here and inquiring as to how you MySQL programmers would handle it.  It's pretty basic - it's more a design thing but it all revolves around the database query.

Given two tables:

notes:
id autoincrement int primary
catid int
...

categories:
id autoincrement int primary
parentid int
...

a record in the note table would correspond to a category and have an id associated with it.  Pretty basic, but the idea behind the categories is to make them nested.   So a list of categories might go like this:

colors (id: 1, parentid: 0)
  dark colors (id:2 parentid: 1)
    brown (id:3 parentid: 2)
    black (id:4 parentid: 2)
  light colors (id: 4 parentid: 1)
     yellow (id: 6 parentid: 4)
     pink (id: 7 parentid: 4)

The trick is, given a category ID, to extract rows from "notes" with that category ID and the id of any subcategories under it in the category table.

Can this be done in a single, MySQL statement?

For example, using the above category layout, if I wanted to pull all rows from notes with category id 1, it would pull everything with category ids from 1-7; if I selected category 2, it would pull records from notes with the category id 2,3 and 4.  If category 6 was selected, only records with that category id would be pulled since it has no sub-categories.  Kind of the scheme that you might see used under Yahoo or eBay's directories.

Assuming that there may be more than 3 levels, what's the best way to handle such a query that would be most efficient?

[+][-]05/11/04 02:51 PM, ID: 11045038Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: MySQL Server
Tags: mysql, category, database, sql
Sign Up Now!
Solution Provided By: snoyes_jw
Participating Experts: 3
Solution Grade: A
 
[+][-]05/11/04 01:24 PM, ID: 11044345Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/11/04 02:00 PM, ID: 11044648Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/11/04 02:08 PM, ID: 11044715Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/11/04 02:12 PM, ID: 11044750Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/11/04 02:23 PM, ID: 11044822Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/11/04 03:05 PM, ID: 11045121Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/11/04 03:22 PM, ID: 11045221Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/12/04 01:08 AM, ID: 11047664Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/13/04 11:53 AM, ID: 11062226Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/13/04 12:57 PM, ID: 11062759Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/14/04 09:21 AM, ID: 11069798Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/14/04 10:39 AM, ID: 11070557Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/06/04 11:44 PM, ID: 11994202Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92