haku Posted March 31, 2008 Share Posted March 31, 2008 I'm having a problem with the following query: SELECT seminars, uploads, full_access FROM authorization WHERE user_id='103' LIMIT 1 I get the following error: Database query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM authorization WHERE user_id='103' LIMIT 1' at line 1 I'm having a stupid moment, because I keep looking at that query, and it keeps looking entirely fine to me. Can someone else maybe point out what is wrong with it? Quote Link to comment Share on other sites More sharing options...
zenag Posted March 31, 2008 Share Posted March 31, 2008 SELECT * FROM authorization WHERE user_id='103' is the correct format Quote Link to comment Share on other sites More sharing options...
zenag Posted March 31, 2008 Share Posted March 31, 2008 limit should be be used in foll format... SELECT * FROM authorization LIMIT 1 SELECT * FROM authorization LIMIT 1,2 ....etc.. Quote Link to comment Share on other sites More sharing options...
uniflare Posted March 31, 2008 Share Posted March 31, 2008 Try: SELECT `seminars`, `uploads`, `full_access` FROM `authorization` WHERE `user_id`='103' LIMIT 1 Limit does not matter if you use it this way, in fact phpmyadmin uses LIMIT 1 syntax regularly. Quote Link to comment Share on other sites More sharing options...
haku Posted April 1, 2008 Author Share Posted April 1, 2008 Zenag: thanks for your help, but using * when retrieving data from the database is *not* a recommended technique. Its overkill - you are pulling every column out of a table, rather than just the ones you need. I suggest you look at my original query to see the proper way of doing it. Uniflare: Thanks for your help as well. The quotes around column names are not necessary, and in fact I didn't end up using them. In the end, my problem was my own stupidity (end of a long day of work - brain was shutting down). The query I posted was entirely right, which is why I was so confused. I was just having a stupid moment - the query I posted wasn't the one generating the error . Quote Link to comment Share on other sites More sharing options...
discomatt Posted April 1, 2008 Share Posted April 1, 2008 Zenag: thanks for your help, but using * when retrieving data from the database is *not* a recommended technique. Its overkill - you are pulling every column out of a table, rather than just the ones you need. I suggest you look at my original query to see the proper way of doing it. This is VERY true and I see too many new devs writing queries like this. Even if selecting every col, it's better to do SELECT `col1`, `col2`, `col3`.... ect. Because SELECT * requires the db to grab the list of columns and THEN perform the query. Quote Link to comment Share on other sites More sharing options...
uniflare Posted April 1, 2008 Share Posted April 1, 2008 thanks for that info disco and haku . i needed every column in my request i dint know it would cause such an overhead the backticksare useful for compatibility, i'm sure new and old version have different "key" words, so using backticks would prevent mysql from giving an error - this is what i have learned as i have made many queries which worked on one bit not the other when i did not use backticks Quote Link to comment Share on other sites More sharing options...
haku Posted April 2, 2008 Author Share Posted April 2, 2008 On that note, I may start using them. Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.