Current location: Hot Scripts Forums » Programming Languages » PHP » complicated SQL statement on my php page


complicated SQL statement on my php page

Reply
  #1 (permalink)  
Old 07-29-10, 09:27 PM
stringrv stringrv is offline
New Member
 
Join Date: Jul 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
complicated SQL statement on my php page

I am trying to make my SQL query do this:

sql Code:
  1. SELECT * FROM b INNER JOIN a ON b.aa = a.aa WHERE b.id = (SELECT choice1 FROM a INNER JOIN ListSelection ON ListSelection.num =a.num WHERE ListSelection.TABLE = 'Level' AND ListSelection.SaveNumber = 123) AND b.id = (SELECT choice2 FROM a INNER JOIN ListSelection ON ListSelection.num = a.num WHERE ListSelection.TABLE = 'Level' AND ListSelection.SaveNumber = 123) AND b.id = (SELECT choice3 FROM a INNER JOIN ListSelection ON ListSelection.num = a.num WHERE ListSelection.TABLE = 'Level' AND ListSelection.SaveNumber = 123) AND b.id = (SELECT choice4 FROM a INNER JOIN ListSelection ON ListSelection.num = a.num WHERE ListSelection.TABLE = 'Level' AND ListSelection.SaveNumber = 123)

This is trying to accplish the following.

A table that has four choices that all refer to numbers from one field in another table.

List B is selecting within the constraints of what was selected in List A. The results display all the FOUR choices (found in the corresponding records) for each of the items from List A. The selections from List A were saved to a table called ListSelection. List A was limited by the selections made and saved to a table called Level which represents the first List that was chosen. So lists in order: List Level > ListA > ListB

Last edited by Nico; 07-30-10 at 03:54 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-29-10, 09:29 PM
stringrv stringrv is offline
New Member
 
Join Date: Jul 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
One problem I know exists is that I am referencing fields that are not selected in my subquery. Any help will be greatly appreciated!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-30-10, 08:27 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
Try it something like this:
Code:
SELECT 
		b.* 
	FROM
		b, a
	ON
		b.aa = a.aa
	WHERE
		b.id 
	IN (
			SELECT 
				a.choice1,a.choice2,a.choice3,a.choice4 
			FROM 
				a, ListSelection 
			ON 
				ListSelection.num = a. num 
			WHERE 
				ListSelection.`TABLE` = 'Level' 
			AND 
				ListSelection.SaveNumber = 123
		)
Let me know how it turns out, it may need to be tweaked.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks

Tags
php, sql, sql query, sql statement


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to call jquery cookie element in PHP page shan_emails PHP 1 02-28-10 01:48 AM
PHP for dummies: form to sql to html page northernsky Script Requests 9 03-12-09 09:45 PM
How do you output PHP on index page. 9999 PHP 4 07-25-06 09:57 PM
Trying to echo PHP code from SQL and run it. And failing. Sheldon PHP 4 08-01-05 12:22 PM
change my field in this example sal21 ASP 3 07-14-03 03:49 AM


All times are GMT -5. The time now is 09:07 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.