format

A

Anonymous

Guest
Can anybody tell me what is the propose for a select like this:

SELECT *,format - 1 as bol_format
FROM ...

I don't know the meaning of 'format'.

Thanks.
 
maktub said:
SELECT *,format - 1 as bol_format
FROM ...

Please take a look at the documentation for SELECT Syntax. It will tell you that everything after SELECT (and certain keywords) is part of the select_expression, which describes what data to return. Most often, this is just a list of columns. You can use * to designate all columns, but this is not a recommended approach. In the example you presented, after the *, it has 'format - 1 AS bol_format'. 'format - 1' is just a mathematical expression which says "take the value in the column named 'format' and subtract one from it. The AS keyword just renames the value when it is returned, so in this case instead of being named 'format - 1', the column will be named 'bol_format' in the output. Here's an example to demonstrate:

Code:
SELECT format FROM table1;
+--------+
| format |
+--------+
| 5      |
+--------+

SELECT format - 1 FROM table1;
+------------+
| format - 1 |
+------------+
| 4          |
+------------+

SELECT format - 1 AS bol_format FROM table1;
+------------+
| bol_format |
+------------+
| 4          |
+------------+
 
Thanks, but format isn't the name of any column data so I don't know if it's a function or something like that for MySQL.
 
The table is this:

CREATE TABLE shoutbox_demo (
id mediumint(8) unsigned NOT NULL auto_increment,
channel varchar(25) NOT NULL default '',
screenname varchar(25) NOT NULL default 'anonymous',
remote_addr varchar(15) NOT NULL default '',
user_agent varchar(255) NOT NULL default '',
timestamp int(11) NOT NULL default '0',
message text NOT NULL,
PRIMARY KEY (id),
KEY channel (channel)
) TYPE=MyISAM COMMENT='PHP ShoutBox';
 
'format' is not a MySQL keyword, so unless it's the name of a column, having it anywhere in your SELECT statement (except quoted, of course) will cause an error.

Maybe if you could post the whole query, we could get more insight into this.
 
Back
Top