Re: [PHP] help with sql statement
On 12 July 2010 18:34, Tommy Pham tommy...@gmail.com wrote: SELECT srs.Name FROM SMS_R_System srs WHERE srs.SystemOUName IN (example.com/COMPUTERS/MAIN CAMPUS/ABC, example.com/COMPUTERS/MAIN CAMPUS/XYZ) As this is a single table query, there is no need for the table alias. SELECT Name FROM SMS_R_System WHERE LEFT(SystemOUName, 34) = 'example.com/COMPUTERS/MAIN CAMPUS/' AND RIGHT(SystemOUName, 3) IN ('ABC', 'XYZ') But this will probably take a measurable amount of time longer to execute - 2 comparisons and 2 string processes. Maybe not for a single run, but after several hundred. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] help with sql statement
I was google searching, and the only SQL mailing list I found is currently giving a 503 error, so I hope you don't mind me asking my SQL question here, since there are a lot of SQL gurus here. I am having a syntax problem: Instead of doing a query like this:: select SMS_R_SYSTEM.Name from SMS_R_System where (SMS_R_System.SystemOUName = example.com/COMPUTERS/MAIN CAMPUS/ABC) or (SMS_R_System.SystemOUName = example.com/COMPUTERS/MAIN CAMPUS/XYZ) I'd like to shorten it in the where clause to: select SMS_R_SYSTEM.Name from SMS_R_System where (SMS_R_System.SystemOUName = example.com/COMPUTERS/MAIN CAMPUS/ABC, example.com/COMPUTERS/MAIN CAMPUS/XYZ) But I'm getting a syntax error. Any idea why my SQL syntax isn't valid? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] help with sql statement
On Mon, 2010-07-12 at 10:24 -0500, Adam wrote: I was google searching, and the only SQL mailing list I found is currently giving a 503 error, so I hope you don't mind me asking my SQL question here, since there are a lot of SQL gurus here. I am having a syntax problem: Instead of doing a query like this:: select SMS_R_SYSTEM.Name from SMS_R_System where (SMS_R_System.SystemOUName = example.com/COMPUTERS/MAIN CAMPUS/ABC) or (SMS_R_System.SystemOUName = example.com/COMPUTERS/MAIN CAMPUS/XYZ) I'd like to shorten it in the where clause to: select SMS_R_SYSTEM.Name from SMS_R_System where (SMS_R_System.SystemOUName = example.com/COMPUTERS/MAIN CAMPUS/ABC, example.com/COMPUTERS/MAIN CAMPUS/XYZ) But I'm getting a syntax error. Any idea why my SQL syntax isn't valid? The short answer is your syntax isn't valid, which means that what you've written isn't valid SQL :p What I think you're looking for instead is something like this: SELECT SMS_R_SYSTEM.Name FROM SMS_R_System WHERE SMS_R_System.SystemOUName IN (example.com/COMPUTERS/MAIN CAMPUS/ABC, example.com/COMPUTERS/MAIN CAMPUS/XYZ) which lets MySQL compare the field against an array of different values within the brackets. Thanks, Ash http://www.ashleysheridan.co.uk
RE: [PHP] help with sql statement
-Original Message- From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] Sent: Monday, July 12, 2010 8:26 AM To: Adam Cc: PHP General Subject: Re: [PHP] help with sql statement On Mon, 2010-07-12 at 10:24 -0500, Adam wrote: I was google searching, and the only SQL mailing list I found is currently giving a 503 error, so I hope you don't mind me asking my SQL question here, since there are a lot of SQL gurus here. I am having a syntax problem: Instead of doing a query like this:: select SMS_R_SYSTEM.Name from SMS_R_System where (SMS_R_System.SystemOUName = example.com/COMPUTERS/MAIN CAMPUS/ABC) or (SMS_R_System.SystemOUName = example.com/COMPUTERS/MAIN CAMPUS/XYZ) I'd like to shorten it in the where clause to: select SMS_R_SYSTEM.Name from SMS_R_System where (SMS_R_System.SystemOUName = example.com/COMPUTERS/MAIN CAMPUS/ABC, example.com/COMPUTERS/MAIN CAMPUS/XYZ) But I'm getting a syntax error. Any idea why my SQL syntax isn't valid? The short answer is your syntax isn't valid, which means that what you've written isn't valid SQL :p What I think you're looking for instead is something like this: SELECT SMS_R_SYSTEM.Name FROM SMS_R_System WHERE SMS_R_System.SystemOUName IN (example.com/COMPUTERS/MAIN CAMPUS/ABC, example.com/COMPUTERS/MAIN CAMPUS/XYZ) Even shorter ;) SELECT srs.Name FROM SMS_R_System srs WHERE srs.SystemOUName IN (example.com/COMPUTERS/MAIN CAMPUS/ABC, example.com/COMPUTERS/MAIN CAMPUS/XYZ) which lets MySQL compare the field against an array of different values within the brackets. Given his syntax, I'd guess that his RDBMS is MS SQL and he's trying to get some info from the DB that's populated by MS' SMS. Regards, Tommy Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with SQL statement
On Thu, 2005-02-17 at 23:21, Jacques wrote: How can I determine which users have signed in and are still on-line during the first minute after they have signed in? My sql statement currently reads: SELECT * FROM tblusers WHERE usignedin = yes AND utimesignedin = (time() - 60) Hoe does one indicate seconds in a SQL statement? Can I use the time() function or should I use the now() function rather? Thanks Jacques I almost do not know where to begin. What database are you using? The functions you need to be looking at are going to be executed by the dbms not php. Look in the dbms docs for the time functions available. Are you really interested in users who logged in exactly 60 seconds ago ( you are using = afterall )? if course this also depends on what type of data is stored in utimesignedin if it is a timestamp with the resolution in seconds then you should be good to go with the whatever_database_function_returns_the_current_timestamp() - 60 deal. Bret -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Help with SQL statement
How can I determine which users have signed in and are still on-line during the first minute after they have signed in? My sql statement currently reads: SELECT * FROM tblusers WHERE usignedin = yes AND utimesignedin = (time() - 60) Hoe does one indicate seconds in a SQL statement? Can I use the time() function or should I use the now() function rather? Thanks Jacques -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Help with SQL statement
I have a database that holds a start date and an end date and I have a form with a start date and an end date. The report would be to get everything in the database's date ranges that overlap the form's date range. I am having trouble figuring out how to get this to work, any help is appreciated. Sarah -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with SQL statement
On Mon, 03 Mar 2003 12:04:37 -0800, you wrote: I have a database that holds a start date and an end date and I have a form with a start date and an end date. The report would be to get everything in the database's date ranges that overlap the form's date range. I am having trouble figuring out how to get this to work, any help is appreciated. [if I understand you correctly] you have 4 variables db_start db_end form_start form_end and you want to select all rows where the range (db_start to db_end) overlaps in any way with (form_start to form_end)? You need two conditions, joined with an OR (form_start = db_start AND form_start = db_end) OR (form_end = db_start AND form_end = db_end) (BTW, this is an SQL question, not a PHP one.) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php