my sql不支持 selete top 1 语句吗?现在有个需求,写一个函数,里面有个查询语句,只需返回一条记录的值
select colval into ret from testtab where ...
这条语句ret可能会有多条记录
我现在只取第一条,返回
咋实现

解决方案 »

  1.   

    my sql不支持 selete top 1 语句吗?不支持select colval into ret from testtab where .. order by ...  limit 1
      

  2.   

    谢谢楼上。my sql有没有个类似ms sqlserver的 print函数SELECT count(*) into @a FROM tab.element;
    print @a
    我想看 @a的值
      

  3.   

    mysql没有top功能,只能select * from table order by 字段 desc 或 asc limit 1
      

  4.   

    直接SELECT就行了。select @a;
      

  5.   

    MySQL官方文档 http://dev.mysql.com/doc/refman/5.1/zh/index.html
      

  6.   

    select colval into @ret from testtab where ...
    select @ret;
      

  7.   

    我使用 mysql query browser工具写查询语句的SELECT count(*) into @a FROM tab.element;
    SELECT @a;按上面这样输入,结果是 NULL, 而正常查询count(*)的时候有值
      

  8.   

    select colval into @ret from testtab where .. order by ... limit 1;
    SELECT @RET;