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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |