Reputation: 385
How do I select only 1 row in sybase without using rowcount
? I don't have the privilege to set rowcount
in sybase. Is there a way to select only 1 row?
For example:
select * from table where name = 'jack'
This returns two rows; how do I select only one row from the result set without using set rowcount
?
Upvotes: 1
Views: 38019
Reputation: 1
If you want a single result, use 'GROUP BY' and 'HAVING column = max(column)'. Or replace max() with min(). This should work unless the max or min values are also not unique.
Upvotes: 0
Reputation: 1225
There seems to be a reason, why you're getting more than 1 row for "WHERE name = 'jack'", it looks as if the rows differ.
But if, the rows do not differ you can try adding "distinct":
SELECT DISTINCT * FROM TABLE WHERE name = 'jack'
or try with "GROUP BY" statement, then you should type explicitly all columns, eg.:
SELECT name FROM TABLE WHERE name = 'jack' GROUP BY name
if this is not what you wanted, can you paste here how the 2 rows look exactly?
Upvotes: 0
Reputation: 2787
Try the query:
SELECT TOP 1 * FROM mytable
WHERE name = 'jack'
As you might guess, this selects the TOP 1 matching results. If you wanted more (which you don't here) you could use any number (TOP 100
or TOP 1000
, etc).
A more comprehensive example can be found on w3schools: http://www.w3schools.com/Sql/sql_top.asp
Upvotes: 11