is the FROM clause necessary in every SELECT statement?Thanks..
Not really - you can use SELECT to initialize a variable.
Examples from here:
mysql> SELECT 1 + 1; -> 2
Not in MySQL, no. You could do this:
SELECT 1 + 1;
It will be in some DBMSs though - Oracle for example would require you to do:
SELECT 1 + 1 FROM DUAL;
(EDIT: Missed the the MYSQL tab.)
This depends on the database.
In Oracle, IIRC, the from is required. But Oracle has a table DUAL which always returns one row for cases where all the work is being done in the SELECT clause.
On the other hand, SQL Server does not require the FROM, to return the value of a variable just select it:
SELECT @myVar
As mentioned by ocedecio FROM is not required in every statement.
For example I tend to use the following syntax to initialise a table with data
insert into status(code, description)
select 'O', 'Open'
union all select 'C', 'Closed'
union all select 'P', 'Parked'
etc..
EDIT (following comments by gamecat)
The example above demonstrates when SELECT without FROM may have a practical use. You can of course just call:
select 'O', 'Open'
union all select 'C', 'Closed'
union all select 'P', 'Parked'
Basically in SQL server 2005 FROM keyword is not required for Scalar value functions and system functions but it mandatory for table valued functions.
Scalar valued functions can executable like below syntax
Select functionname(arguments)
Table valued functions can executable like below syntax
Select * from functionname(arguments)
else
Select col1,col2 from functionname(argument1,argument2)