Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: mysql shorthand

  1. #1
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,740
    Thanks
    82
    Thanked 90 Times in 88 Posts

    Default mysql shorthand

    Is there a way to use shorthand for the following:

    Code:
    SELECT * FROM table WHERE col != 'this' AND col != 'that'
    This would be rather handy when I want to filter out some of the results.
    Last edited by james438; 01-08-2012 at 06:56 PM.
    To choose the lesser of two evils is still to choose evil. My personal site

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I don't think so. You could use regex if you wanted but that would take longer.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,740
    Thanks
    82
    Thanked 90 Times in 88 Posts

    Default

    What I mean is could I replace
    Code:
    SELECT * FROM table WHERE col != 'this' AND col != 'that'
    with something like
    Code:
    SELECT * FROM table WHERE col != 'this','this1','this2'
    or
    Code:
    SELECT * FROM table WHERE col != 'this'||'this1'||'this2'
    or even
    Code:
    SELECT * FROM table WHERE col != $array
    To choose the lesser of two evils is still to choose evil. My personal site

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    No. You could use PHP to write the query - makes things like this a snap, if you're doing it dynamically/ more than once.

  5. #5
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,740
    Thanks
    82
    Thanked 90 Times in 88 Posts

    Default

    Bummer, I was hoping MySQL could use some shorthand similar to what PHP uses. For some of my larger scripts I do use PHP to dynamically write the queries. For my website search script the queries can be quite large and numerous depending on the terms and tables searched.
    To choose the lesser of two evils is still to choose evil. My personal site

  6. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    I don't have any experience with this, but if you have access to the MySQL server, you can write stored procedures. Don't know for sure, but I'm sure something like this could be done.

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Well, there are two ways in which (at least in theory) this would be faster:
    1. Faster to write.
    2. Faster to process.

    For (1), you can use PHP to generate it if you'd like.
    For (2), I don't think that having more code in this case actually will be slower. MySQL is very efficient as-is, so a long query isn't a problem, but potentially making a multi-layered query (eg, a stored procedure) might end up being slower since there's more going on.

    So, I don't think this would really help, except saving you the effort of automating the query in PHP.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #8
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,740
    Thanks
    82
    Thanked 90 Times in 88 Posts

    Default

    I'm not really looking for something that is faster. I mostly was looking for a way to make the queries simpler. It would also make it a little easier to add filters to the query as new filters become needed.

    This is in regards to my security monitoring script. I want to add ip addresses to the list that should not pop up in my table as potential security attacks. I have my own ip address and google's filtered out at the moment, but I am sure others will come up in the future.
    To choose the lesser of two evils is still to choose evil. My personal site

  9. #9
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Daniel - stored procedures are actually significantly faster than similar processing in PHP in most cases, since it's native. Obviously, there are a lot of things MySQL can't do for PHP, but the tasks it can do are faster.

  10. The Following User Says Thank You to traq For This Useful Post:

    djr33 (01-10-2012)

  11. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Not to distract too much from the topic, but in what way are they faster? I'm probably missing something. Generally, if the PHP is badly written, I can see that being slow, but if it's a simple scenario where you just want to get a simple search done, I'm not sure why PHP would be slow there.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •