in reply to generated SQL statement problem (OT)

Well, I have very limited experience with MySQL, but, in general (i.e., with the other 5 or 6 DBMSes I've used), you do not have to SELECT a column in order to use it in the WHERE clause. It seems very, very odd to me to think that MySQL would have that kind of restriction.

I'll check over your script in a little more detail and see if I spot anything.

MrCromeDome

Update #2: I deleted my original update as I was totally mistaken. . . I don't use SQL aliasing much, and inadvertantly took you down a wrong path. Albannach pointed it out to me, so vote his nodes up, not mine ;)

He pointed out that you can't use column aliases at all in a WHERE clause. I know your error doesn't specifically seem to relate to an aliasing issue. . . but eliminating the alias never hurts ;) Perhaps try:

select csGroups.ID as groupid,csUsers.UserName as username,csUsers.ID +as id,csGroups_lang.Title as grouptitle from csGroups_lang,csUsers,cs +Groups,csUsers_Groups where csGroups.ID = csGroups_lang.ID and csUser +s.ID = csUsers_Groups.UserID and csGroups.ID = csUsers_Groups.GroupID + and (csUsers.ID IN (1,2)) order by username asc limit 0,10
and see what happens. Hope this helps!
MrCromeDome

Replies are listed 'Best First'.
Re: Re: generated SQL statement problem (OT)
by AidanLee (Chaplain) on Jun 22, 2001 at 23:55 UTC

    I modified my sql statement to this:

    select csGroups.ID as groupid,csUsers.UserName as username, csGroups_lang.Title as grouptitle,csUsers.ID as uid from csGroups_lang,csUsers,csGroups,csUsers_Groups where csGroups.ID = csGroups_lang.ID and csUsers.ID = csUsers_Groups.UserID and csGroups.ID = csUsers_Groups.GroupID and (csUsers.ID IN (1,2)) order by username asc limit 0,10

    and got the same error through my script:

    Unknown column 'csUsers_Groups.UserID' in 'where clause'

    however it ran cleanly from the mysql command line. So something between the database and my script (the dbd driver?) doesn't like it. Odd....