Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
-
raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
-
Contact:
Post
by raghavan20 »
This does not work
Code: Select all
select `UserName`, `Message`
from `ChatMessages_tbl`, `ChatUsers_tbl`
where `ChatMessages_tbl.UserId` = `ChatUsers_tbl.Id`
If I take off the "`" symbol on the fields in the where parameter, it works..why???
Code: Select all
select `UserName`, `Message` from `ChatMessages_tbl`, `ChatUsers_tbl` where
ChatMessages_tbl.UserId = ChatUsers_tbl.Id
Last edited by
raghavan20 on Wed Aug 10, 2005 8:12 am, edited 1 time in total.
-
Skittlewidth
- Forum Contributor
- Posts: 389
- Joined: Wed Nov 06, 2002 9:18 am
- Location: Kent, UK
Post
by Skittlewidth »
To quote burrito:
mysql allows you to use the backticks so that you can use reserved words, operators and keywords for table and field names.
ex:
a field name this-field would not be valid because of the minus (-) sign.
so if you tried this:
Code:
select * from myTable where this-field = 'joe'
the query would bomb out...whereas
Code:
select * from `myTable where `this-field` = 'joe'
would work.
For the rest of this post see
viewtopic.php?t=36594
-
raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
-
Contact:
Post
by raghavan20 »
That was not my problem.
My problem is the query did not work when I had the backticks on; only the second format worked.
It says that this field cannot be found
but this works
-
skhale
- Forum Newbie
- Posts: 6
- Joined: Sat Aug 06, 2005 12:56 pm
- Location: Boston, MA
Post
by skhale »
Use
Make sure the table name has its own backticks and the field name has its own
-
raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
-
Contact:
Post
by raghavan20 »
Oh!!! I did not think of that. It works as you said.
Earlier it was assuming the whole thing(`ChatMessages_tbl.UserId`) to be a field and reported that the field could not be found
Now with backticks on table name, unmarked dot operator and the backticked field name, it works fine.
cheers!!!