vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I can't seem to figure out the query for what seemingly should be an easy thing. I have a table "user" which contains the following columns and data: userid locationid 1 1 2 2 3 1 4 3 I need to return a list of locationid's based on a specific userid's locationid. For example if userid equals 1, the query would return userid location 1 1 3 1 Thanks. |
| |||
| "Bosconian" <bosconian@planetx.com> wrote in message news:w6-dnT2MIerY3DreRVn-rg@comcast.com... > I need to return a list of locationid's based on a specific userid's > locationid. > > For example if userid equals 1, the query would return > > userid location > 1 1 > 3 1 Your description is not clear. Do you mean return all users at the same location as the specified userid? SELECT u2.userid, u2.locationid FROM user AS u INNER JOIN user AS u2 ON u.locationid = u2.locationid WHERE u.userid = 1; Regards, Bill K. |
| ||||
| "Bill Karwin" <bill@karwin.com> wrote in message news:do7gv902d56@enews3.newsguy.com... > "Bosconian" <bosconian@planetx.com> wrote in message > news:w6-dnT2MIerY3DreRVn-rg@comcast.com... > > I need to return a list of locationid's based on a specific userid's > > locationid. > > > > For example if userid equals 1, the query would return > > > > userid location > > 1 1 > > 3 1 > > Your description is not clear. Do you mean return all users at the same > location as the specified userid? > > SELECT u2.userid, u2.locationid > FROM user AS u INNER JOIN user AS u2 > ON u.locationid = u2.locationid > WHERE u.userid = 1; > > Regards, > Bill K. > > Bill, Sorry for the confusing description, but fortunately you were able to decipher my dilemma hopefully with the results example. Your query works like a charm--thanks! |