Breaking up a nested query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
jimmyp3016
Forum Newbie
Posts: 3
Joined: Tue Jan 09, 2007 1:30 pm

Breaking up a nested query

Post by jimmyp3016 »

Hey Guys,

I am running an older verison of sql on my webhost and it does not support nested querys which was enabled in 4.1 i think.

How can I break up this statement so my code will run on my server?

Code: Select all

$sql = "SELECT *, COUNT(id) AS referrals FROM user WHERE id IN (";	
	$sql .= "  SELECT DISTINCT u.referral FROM user u, transaction t WHERE u.id=t.userID";
	$sql .= ") GROUP BY id";
Any help would be great thanks!
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Have you tried joining the tables?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

SQL question :arrow: Databases.
Post Reply