Unix Technical Forum

Easier way then to use a join here?

This is a discussion on Easier way then to use a join here? within the MySQL forums, part of the Database Server Software category; --> I use the following select statement that correctly retrieves the data I want: SELECT * FROM userpref AS pref ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 08:32 AM
ukr_bend@yahoo.com
 
Posts: n/a
Default Easier way then to use a join here?

I use the following select statement that correctly retrieves the data
I want:

SELECT * FROM userpref AS pref
JOIN userpref AS pref2 ON pref2.userid=pref.userid
WHERE ( pref.questionid = '30' and pref.answer = '7507')
and( pref2.questionid = '41' and pref2.answer = '9108' )

The problem is that some of my select statements get rather complicated
and I use a lot of self-joining to the userpref table above, perhaps a
dozen or so self joins. This causes the select statements to really
sloooow down, taking a few minutes in some cases. Since this is used by
a website, this is not a good solution.
I thought I could improve performance if I were to trash the joins
and somehow do all the logic in the WHERE statement as:

SELECT * FROM userpref AS pref
WHERE ( pref.questionid = '30' and pref.answer = '7507')
and ( pref.questionid = '41' and pref.answer = '9108' )

Of course this doens't work, as the same questionid is referenced
twice, but my question is, is there some syntax here that would give
the same result as the join above but without using the join and have
the logic in the where statement alone?
Thanks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:26 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com