[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.

10/27/2009 at 01:10PM PDT, ID: 24848677
[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!

8.1

Problem with MySQL Multi sub query

Asked by jaenglish in SQL Query Syntax, Data Manipulation, MySQL Server

Tags: mysql, multi-sub query

I have an issue with a MySQL query with sub queries where each subquery works independantly but not as a complete solution. I am trying to avoid having to pull a subset of data and using a PHP loop to then pull the additional data.
Scenario:
A table called 'residents' has a field called 'dislikes'. It is a comma-delimited text string, with each element being the ID of a row in another table. What I am trying to do with this query is select that string and converting it into a format that I can use in an 'IN' clause.
The loop in the SQL is governed by a counter with the max value being the length of the table of dislikes, and a 'GROUP BY' in use to restrict the replicated final ID.

I have attached a dump of the 3 tables in use to help understand the query.

The supplied query is supposed to work like this...get a the string 'dislikes' from the resident table where the resident id is 1. Get the ID of the field from the 'dislikes_types' table where the title is 'Vegetables'. Use that ID to get the IDs of the rows in the 'dislikes' table, and then use that data against the residents dislikes string to list the residents dislikes.

Hope that makes sense.

So each sub-query does work, but what is actually happening when they are all put together is that it only returns the last value.

Thanks.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
SELECT md.title 
FROM menu_dislikes md
WHERE md.type_id = ( 
	SELECT mdt.type_id
	FROM menu_dislikes_types mdt
	WHERE mdt.title = 'Vegetables'
 ) AND md.dislike_id IN (
	SELECT SUBSTRING_INDEX(
		SUBSTRING_INDEX(( 
			SELECT dislikes 
			FROM menu_profile 
			WHERE resident_id = 1
		), ',', @r:=@r + 1 ), ',' , -1 ) zxz
	FROM ( SELECT @r:=0 ) x,
	( SELECT dislike_id xx FROM menu_dislikes ) z
	GROUP BY zxz
)
Attachments:
 
SQL dump of tables used in the query
 
[+][-]10/27/09 06:10 PM, ID: 25679198

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.

 
[+][-]10/27/09 06:28 PM, ID: 25679278

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.

 
[+][-]10/27/09 06:43 PM, ID: 25679346

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.

 
[+][-]10/28/09 01:58 AM, ID: 25681074

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

Zones: SQL Query Syntax, Data Manipulation, MySQL Server
Tags: mysql, multi-sub query
Sign Up Now!
Solution Provided By: pcelba
Participating Experts: 1
Solution Grade: B
 
 
[+][-]11/11/09 01:13 PM, ID: 25799133

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.

 
[+][-]11/11/09 01:22 PM, ID: 25799233

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.

 
[+][-]11/11/09 01:33 PM, ID: 25799334

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...
20090824-EE-VQP-74 - Hierarchy / EE_QW_3_20080625