Front Office Football Central  

Go Back   Front Office Football Central > Archives > FOFC Archive
Register FAQ Members List Calendar Mark Forums Read Statistics

Reply
 
Thread Tools
Old 10-06-2005, 11:08 AM   #1
MacroGuru
Coordinator
 
Join Date: May 2003
Location: Utah
Unhappy A little MySQL query help

Alright,

I just wrote the following query:

Code:
SELECT DISTINCT ci.cust_id, ci.first_name, ci.last_name, ci.home_phone, ci.work_phone, ci.mobile,ci.email, ls.lead_source, pi.product_name, oi.order_date, oi.order_id, opd.prod_price FROM cust_info ci LEFT JOIN order_info oi ON ci.cust_id = oi.cust_id LEFT JOIN order_product_details opd ON oi.order_id = opd.order_id LEFT JOIN lead_source ls ON ci.lead_source_id = ls.lead_source_id LEFT JOIN product_info pi ON opd.product_id = pi.product_id WHERE oi.order_status_id IN (1,5) AND oi.order_date >= CURRENT_DATE() -60 AND ci.custi_d not in (select ci2.cust_id from cust_info ci2 LEFT JOIN order_info oi2 ON ci.cust_id = oi.cust_id LEFT JOIN order_product_details opd2 ON oi2.order_id = opd2.order_id WHERE opd2.product_id IN (6,16,26)) Group By ci.cust_id


Just as I run it in MySQL...I found out we are running an outdated version of MySQL that doesn't support subselects.

I need to rewrite this using JOINS....

Now let me say the following....JOINS are not my strong suit, and neither is MySQL.....any help that someone can give me, I would extremely appreciate it....
__________________
"forgetting what is in the past, I strive for the future"

MacroGuru is offline   Reply With Quote
Old 10-06-2005, 01:29 PM   #2
MIJB#19
Coordinator
 
Join Date: Oct 2000
Location: Maassluis, Zuid-Holland, Netherlands
Hate to sound like an ass, but with that many joins, I'm tempted to think your data should be represented differently.
__________________
* 2005 Golden Scribe winner for best FOF Dynasty about IHOF's Maassluis Merchantmen
* Former GM of GEFL's Houston Oilers and WOOF's Curacao Cocktail
MIJB#19 is offline   Reply With Quote
Old 10-06-2005, 01:42 PM   #3
cartman
Death Herald
 
Join Date: Nov 2000
Location: Le stelle la notte sono grandi e luminose nel cuore profondo del Texas
I've been looking at this for a while now, and I don't see a way to do it without using a subselect.
__________________
Thinkin' of a master plan
'Cuz ain't nuthin' but sweat inside my hand
So I dig into my pocket, all my money is spent
So I dig deeper but still comin' up with lint
cartman is offline   Reply With Quote
Old 10-06-2005, 01:54 PM   #4
Telle
College Starter
 
Join Date: Feb 2004
Location: Buffalo, NY
The "not in" clause usually (always?) cannot be replaced by a join. Same thing with "not exists".
Telle is offline   Reply With Quote
Old 10-06-2005, 03:34 PM   #5
MacroGuru
Coordinator
 
Join Date: May 2003
Location: Utah
Quote:
Originally Posted by MIJB#19
Hate to sound like an ass, but with that many joins, I'm tempted to think your data should be represented differently.

Yeah I know...it's why I am here.....I am rebuilding the system, moving from the PHP/MySQL solution they have been using and rolling to an MS SQL and .NET.

But in the meantime I am stuck supporting and snagging data for people out of this system. I figured out how to do it, but I need root access to the machine, and the MIS guys have said no, they will upgrade MySQL to 4.1 for me

Thanks for looking and trying to help me out here guys,.....
__________________
"forgetting what is in the past, I strive for the future"
MacroGuru is offline   Reply With Quote
Old 10-06-2005, 03:40 PM   #6
PackerFanatic
Pro Starter
 
Join Date: Jul 2005
Location: Appleton, WI
I will take a look and see what I can come up with.
__________________
Commissioner of the RNFL
PackerFanatic is offline   Reply With Quote
Old 10-06-2005, 03:57 PM   #7
PackerFanatic
Pro Starter
 
Join Date: Jul 2005
Location: Appleton, WI
Would you be able to create a view using that subselect you have and then left join your cust_id against that, checking for cust_ids not in that view...

ci.cust_id LEFT JOIN your view yv ON ci.cust_id <> yv.cust_id

Not sure how well that would work...
__________________
Commissioner of the RNFL
PackerFanatic is offline   Reply With Quote
Old 10-06-2005, 04:05 PM   #8
MacroGuru
Coordinator
 
Join Date: May 2003
Location: Utah
Quote:
Originally Posted by PackerFanatic
Would you be able to create a view using that subselect you have and then left join your cust_id against that, checking for cust_ids not in that view...

ci.cust_id LEFT JOIN your view yv ON ci.cust_id <> yv.cust_id

Not sure how well that would work...

Would love to....but they are not supported in MySQL.....
__________________
"forgetting what is in the past, I strive for the future"
MacroGuru is offline   Reply With Quote
Old 10-06-2005, 04:09 PM   #9
MO542
n00b
 
Join Date: Mar 2005
Quote:
Originally Posted by indoorsoccersim
Would love to....but they are not supported in MySQL.....

If it doesn’t support inline views, then I’d create a temp table with the select statement in the subquery. Then I’d join those tables together.
MO542 is offline   Reply With Quote
Old 10-06-2005, 04:12 PM   #10
PackerFanatic
Pro Starter
 
Join Date: Jul 2005
Location: Appleton, WI
Views aren't supported either? Shitty, heh...
__________________
Commissioner of the RNFL
PackerFanatic is offline   Reply With Quote
Reply


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

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Forum Jump


All times are GMT -5. The time now is 08:34 AM.



Powered by vBulletin Version 3.6.0
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.