473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Complex nested mySql query help needed.

verbatim
i have 4 tables in a db, to allow users rate certain recipes. they might not rate all recipes at one time. they might even go back and rate a recipe more than one time. there will also be at least 1, and up to 4 kids participating in voting for each recipe.

i would like to determine the first 100 moms to rate all X recipes using the date of submission of the vote of the final recipe as qualifier. (meaning a mom would get added to the list of 100 after she rates all recipes from the recipes table)

it seems it will either take a complex nested query, or several queries mixed in with php

below are the 4 tables.

any help would be appreciated.

recipes_db
-- recipe_id
-- recipe_name

mom_form
-- user_id
-- firstname
-- lastname
-- phonenumber
-- address
-- city
-- state
-- zipcode
-- timestamp

mom_comments
-- comment_id
-- user_id
-- recipe_id
-- favorite_recipe
-- moms_comments
-- childname1
-- childage1
-- child_comments1
-- childname2
-- childage2
-- child_comments2
-- childname3
-- childage3
-- child_comments3
-- childname4
-- childage4
-- child_comments4
-- timestamp

mom_votes
-- votes_id
-- rating
-- user_id
-- recipe_id
-- timestamp
Feb 27 '08 #1
4 1843
chaarmann
785 Expert 512MB
You posted your assignment, fine. But did you also read the forum guideline?
So what's your question? How can we help?
Just post the SQL or code where you have difficulties with.


i have 4 tables in a db, to allow users rate certain recipes. they might not rate all recipes at one time. they might even go back and rate a recipe more than one time. there will also be at least 1, and up to 4 kids participating in voting for each recipe.

i would like to determine the first 100 moms to rate all X recipes using the date of submission of the vote of the final recipe as qualifier. (meaning a mom would get added to the list of 100 after she rates all recipes from the recipes table)

it seems it will either take a complex nested query, or several queries mixed in with php

below are the 4 tables.

any help would be appreciated.

recipes_db
-- recipe_id
-- recipe_name

mom_form
-- user_id
-- firstname
-- lastname
-- phonenumber
-- address
-- city
-- state
-- zipcode
-- timestamp

mom_comments
-- comment_id
-- user_id
-- recipe_id
-- favorite_recipe
-- moms_comments
-- childname1
-- childage1
-- child_comments1
-- childname2
-- childage2
-- child_comments2
-- childname3
-- childage3
-- child_comments3
-- childname4
-- childage4
-- child_comments4
-- timestamp

mom_votes
-- votes_id
-- rating
-- user_id
-- recipe_id
-- timestamp
Feb 27 '08 #2
ronverdonk
4,258 Expert 4TB
Just subscribing.

Ronald
Feb 27 '08 #3
i was wondering if anyone might be able to determine a complex query based on the tables above, or if a concensus might be to break it up into smaller queries, the results of which might then be examined together with php.

my query: find the first 100 moms who rate X recipes as determined by the timestamp of the last (last for that user) submitted rating. the user might not rate all recipe in one sitting. they might rate them over several days.

So if there are 3 recipes to rate, a user enters (or doesn't enter) the list of 100 according to the timestamp of the third entry.


as i mentioned previously, i'm not sure if this can be accomplished in large complex (nested?) query, or it will require several separate queries.

i haven't really written any queries yet. I have written a few small queries that might do one part or other of the larger goal. the one or two attempts i have made at a large unified query, have not at all been successful and are not yet even worth posting.

thanks for any help.
Feb 27 '08 #4
chaarmann
785 Expert 512MB
i was wondering if anyone might be able to determine a complex query based on the tables above, or if a concensus might be to break it up into smaller queries, the results of which might then be examined together with php.

my query: find the first 100 moms who rate X recipes as determined by the timestamp of the last (last for that user) submitted rating. the user might not rate all recipe in one sitting. they might rate them over several days.

So if there are 3 recipes to rate, a user enters (or doesn't enter) the list of 100 according to the timestamp of the third entry.


as i mentioned previously, i'm not sure if this can be accomplished in large complex (nested?) query, or it will require several separate queries.

i haven't really written any queries yet. I have written a few small queries that might do one part or other of the larger goal. the one or two attempts i have made at a large unified query, have not at all been successful and are not yet even worth posting.

thanks for any help.
You can write all in one huge SQl, but I wouldn't do it. Because it makes the program very hard to understand for people who come after you and need to change the code. I have enough experience that I can tell you that even you would not understand your own SQL anymore if you look at it a year later or so. Also it makes it run very slow and puts a heavy load on the database.
Having many small SQLs instead are much, much better.
Just develop them and post them one by one if you have problems with them.
I can help you if you are stuck, for example if you don't know how to code the "find the first 100 moms" condition.
Then I would answer you, make the SQL that gets them all, let's call it "yourSqlStatement " and wrap around:
Expand|Select|Wrap|Line Numbers
  1. select * from ( yourSqlStatement ) where rownum <= 100;
But I will not give you complete solutions, only help. Because it's your work and you will not learn otherwise.
Feb 27 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Simon | last post by:
Hi, I am having a little problem with my PHP - MySQl code, I have two tables (shown below) and I am trying populate a template page with data from both. <disclaimer>Now I would like to say my...
5
by: Colman | last post by:
Howdy all! I guess I'm a newbie, because I am stumped (or maybe just too durned tired). Here's what I got... CREATE TABLE `nodecat_map` ( `nodecat_id` mediumint(8) unsigned NOT NULL...
3
by: Marcus | last post by:
Hi I have a very complex sql query and a explain plan. I found there is a full table scan in ID=9 9 8 TABLE ACCESS (FULL) OF 'F_LOTTXNHIST' (Cost=84573 Card=185892...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
8
by: Steve Jorgensen | last post by:
Mailing List management is a good example of a case where my conundrum arises. Say there is a m-m relationship between parties and groups - anyone can be a member of any combintation of groups. ...
9
by: Robert W. | last post by:
I have built several kinds of complex classes that I work with in my program. Storing them to disk is no problem because I just pass the instantiated object to a SaveData method, accepting it as a...
1
by: Good Man | last post by:
Hi there I've noticed some very weird things happening with my current MySQL setup on my XP Laptop, a development machine. For a while, I have been trying to get the MySQL cache to work....
0
bugboy
by: bugboy | last post by:
I'm experimenting with the "Nested Set" type structure for holding hierarchical data in mysql. This is my refrence: http://dev.mysql.com/tech-resources/articles/hierarchical-data.html When i...
3
by: BUmed | last post by:
Ok let me start from the start. I have a form that has question in it and the person chooses 0 1 2 -99 for each. The form then needs to add up the numbers for the sub categories in the form. For...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.