|
-
Jul 4th, 2002, 09:47 PM
#1
Thread Starter
Hyperactive Member
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?
-
Jul 4th, 2002, 09:55 PM
#2
Member
MySQL 3.x doesn't support nested queries, so it's not legal. The CVS for MySQL 4 should.
-
Jul 4th, 2002, 09:57 PM
#3
Member
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.
-
Jul 4th, 2002, 10:06 PM
#4
Thread Starter
Hyperactive Member
thats for the imput filburt
-
Jul 5th, 2002, 07:37 PM
#5
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
-
Jul 5th, 2002, 07:44 PM
#6
Thread Starter
Hyperactive Member
so my statement above would work right?
-
Jul 5th, 2002, 07:46 PM
#7
should, did you try it. the worse thing that will happen is it will error out
-
Jul 5th, 2002, 07:58 PM
#8
Member
Bull dude, tried this:
Code:
SELECT SQRT(SELECT 9)
Simple, but doesn't work. It hurls on the other SELECT.
-
Jul 5th, 2002, 08:00 PM
#9
Member
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)
-
Jul 5th, 2002, 08:37 PM
#10
what format is that
SELECT SQRT(SELECT 9)
select what from what. you didn't tell mysql what teh hell you are doing.
-
Jul 5th, 2002, 09:28 PM
#11
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|