Results 1 to 11 of 11

Thread: Is this sql legal?

  1. #1

    Thread Starter
    Hyperactive Member Kagey's Avatar
    Join Date
    Sep 2000
    Location
    The Wilderness of New Brunswick
    Posts
    294

    Is this sql legal?

    when using mySQL, is it possible to do the following insert:

    Code:
    INSERT INTO address(state_id, name, email)
    VALUES( (SELECT state_id FROM states WHERE abbreviation = 'WC'), 'Joe Blow', '[email protected]');
    where i get the id from the "inner" querry.

    is this legal or s there a better way of doing it?

    oh and another thing, what is concidered to be the proper and best way to document a function and a class?

  2. #2
    MySQL 3.x doesn't support nested queries, so it's not legal. The CVS for MySQL 4 should.

  3. #3

    Re: Is this sql legal?

    Originally posted by Kagey
    oh and another thing, what is concidered to be the proper and best way to document a function and a class?
    I used to document things Javadoc-style:

    PHP Code:
    /**
     * Does stuff.
     *
     * @param somearg Used in the function for stuff.
     * @return Whatever somearg is
     */
    function dostuff($somearg)
    {
        return 
    $somearg;

    Now, if I comment the function at all, I just do:
    PHP Code:
    function dostuff($somearg)
    // Returns $somearg
    {
        return 
    $somearg;

    Obviously there's no right or wrong way of doing it, it's your preference.

  4. #4

    Thread Starter
    Hyperactive Member Kagey's Avatar
    Join Date
    Sep 2000
    Location
    The Wilderness of New Brunswick
    Posts
    294
    thats for the imput filburt

  5. #5
    scoutt
    Guest
    Originally posted by filburt1
    MySQL 3.x doesn't support nested queries, so it's not legal. The CVS for MySQL 4 should.
    better go back to reading Arien. mysql3.xx suppurts it.

    http://www.mysql.com/doc/A/N/ANSI_diff_Sub-selects.html

  6. #6

    Thread Starter
    Hyperactive Member Kagey's Avatar
    Join Date
    Sep 2000
    Location
    The Wilderness of New Brunswick
    Posts
    294
    so my statement above would work right?

  7. #7
    scoutt
    Guest
    should, did you try it. the worse thing that will happen is it will error out

  8. #8
    Originally posted by scoutt

    better go back to reading Arien. mysql3.xx suppurts it.

    http://www.mysql.com/doc/A/N/ANSI_diff_Sub-selects.html
    Bull dude, tried this:
    Code:
    SELECT SQRT(SELECT 9)
    Simple, but doesn't work. It hurls on the other SELECT.

  9. #9
    Code:
    mysql> SELECT SQRT(SELECT 9);
    ERROR 1064: You have an error in your SQL syntax near 'SELECT 9)' at line 1
    mysql> SELECT SQRT('SELECT 9');
    +------------------+
    | SQRT('SELECT 9') |
    +------------------+
    |         0.000000 |
    +------------------+
    1 row in set (0.00 sec)
    
    mysql> SELECT SQRT("SELECT 9");
    +------------------+
    | SQRT("SELECT 9") |
    +------------------+
    |         0.000000 |
    +------------------+
    1 row in set (0.00 sec)
    
    mysql> SELECT SQRT(9);
    +----------+
    | SQRT(9)  |
    +----------+
    | 3.000000 |
    +----------+
    1 row in set (0.00 sec)

  10. #10
    scoutt
    Guest
    what format is that

    SELECT SQRT(SELECT 9)


    select what from what. you didn't tell mysql what teh hell you are doing.

  11. #11
    Originally posted by scoutt
    what format is that

    SELECT SQRT(SELECT 9)


    select what from what. you didn't tell mysql what teh hell you are doing.
    SELECT may also be used to retrieve rows computed without reference to any table. For example:

    mysql> SELECT 1 + 1;
    -> 2
    Still SELECT 9 works too, it outputs "9".

Posting Permissions

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



Click Here to Expand Forum to Full Width