如何选择字段的默认值 [英] How to SELECT DEFAULT value of a field
本文介绍了如何选择字段的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我似乎找不到或编写一个选择默认值的sqlquery
I can't seem to find or write a sqlquery that SELECTS the DEFAULT VALUE
(而且我认为我无法在phpmyadmin中生成它以便复制)
(and I don't think I can generate it in phpmyadmin for me to copy)
我试图选择它,就好像它是一条记录,但无济于事...
I tried to SELECT it as if it was a record but to no avail...
$defaultValue_find = mysql_query(
"SELECT $group FROM grouptable WHERE $group='DEFAULT'")
or die("Query failed:".mysql_error());
$defaultValue_fetch = mysql_fetch_row($defaultValue_find);
$defaultValue = $defaultValue_fetch[0];
echo $defaultValue;
推荐答案
"SELECT $group FROM grouptable WHERE $group=DEFAULT( $group ) "
或者我认为更好:
"SELECT DEFAULT( $group ) FROM grouptable LIMIT 1 "
更新-更正
正如@Jeff Caron指出的那样,以上内容仅在grouptable
中至少有1行的情况下有效.如果即使分组表没有行也要得到结果,则可以使用以下方法:
As @Jeff Caron pointed, the above will only work if there is at least 1 row in grouptable
. If you want the result even if the grouptable has no rows, you can use this:
"SELECT DEFAULT( $group )
FROM (SELECT 1) AS dummy
LEFT JOIN grouptable
ON True
LIMIT 1 ;"
这篇关于如何选择字段的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文