×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to limit the sql to reurn only 1 result

How to limit the sql to reurn only 1 result

How to limit the sql to reurn only 1 result

(OP)
Hey,

My application give the user the ability to create a virtual view.

The user insert a query - "selcet product_id from product" and we show him the structre of this virtual view.

In order to get the column types i run this query than get the "ResultSetMetaData" ( by getMetaData() ) and finally get the column type from the ResultSetMetaData.

I dont need the full results for the query, so i want to limit the results for 1.
Does any one has an idea?

Thank you

RE: How to limit the sql to reurn only 1 result

Select Top 1 product_id from product

I tried to have patience but it took to long! smile  -DW

RE: How to limit the sql to reurn only 1 result

Which database engine is your user using? Is it Access, Oracle, SQL Server etc?  There are various solutions, but they are engine specific.

John

RE: How to limit the sql to reurn only 1 result

(OP)
I need a generic solution.
currently i solved it by setting stmt.setMaxRows(1), but i read that it dosnt gurrenty better performance .

RE: How to limit the sql to reurn only 1 result

Quote:


I need a generic solution.
There is no generic solution.

If you can tell us which database you are using then perhaps somebody will be able to help.

Geoff Franklin
www.alvechurchdata.co.uk

RE: How to limit the sql to reurn only 1 result

jadams0173's solution will work in Microsoft databases (Access or SQL server). Probably the nearest to a completely database engine independent solution is something like:

SELECT min (product_id) As [Product ID]
FROM product
WHERE condition

Important: You must set the where clause here to only retrieve data from the rows that you need, or you will get the smallest product ID in the table every time.

John

RE: How to limit the sql to reurn only 1 result

And if you have multiple records then what criteria determines which one you show? Ids it the newest one, the oldest one or the one with a specific value in one field? This can dictate waht you add to the query in where clause to get the proper results.

Questions about posting. See FAQ183-874

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close