CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
HOw to write sql for get top 100 record in CGI perl script?

 



avian
New User

Nov 7, 2013, 4:17 AM

Post #1 of 6 (1258 views)
HOw to write sql for get top 100 record in CGI perl script? Can't Post

Hello

In one of my CGI script, I wrote a query as

$DQL = "select * from $OBJECT_TYPE where folder(\'$ROOT_FOLDER\',descend) " ;

Now I want to fetch top 100 records, so I tried like

$DQL = "select * from $OBJECT_TYPE where folder(\'$ROOT_FOLDER\',descend) limit 100" ;

It is returning error error, Then I tried as

$DQL = "select TOP 100 from $OBJECT_TYPE where folder(\'$ROOT_FOLDER\',descend) " ;

but it is also giving error, I am sure I am not writing query in correct format, can any one suggest how Can I do this?

Avian


BillKSmith
Veteran

Nov 7, 2013, 5:34 AM

Post #2 of 6 (1255 views)
Re: [avian] HOw to write sql for get top 100 record in CGI perl script? [In reply to] Can't Post

I do not know how to do this in SQL. However, it would be easy to use your first select statement and then filter the data with perl. (I think you just want to fetch the first 100 rows.)
Good Luck,
Bill


avian
New User

Nov 7, 2013, 6:55 AM

Post #3 of 6 (1251 views)
Re: [BillKSmith] HOw to write sql for get top 100 record in CGI perl script? [In reply to] Can't Post

Hi

I am novice programmer, can you suggest how can I filter the data?

Avian


FishMonger
Veteran / Moderator

Nov 7, 2013, 8:10 AM

Post #4 of 6 (1249 views)
Re: [avian] HOw to write sql for get top 100 record in CGI perl script? [In reply to] Can't Post

I'm not familiar with that where clause syntax.

Does that first select statement work, or does it produce an error?

What database are you using and what DB module are you using?

What do you mean by "fetch top 100 records"? Do you want to simply select the first 100 records, or is there a "ranking" field that you need to order by and limit the number of returned records?


BillKSmith
Veteran

Nov 7, 2013, 10:40 AM

Post #5 of 6 (1246 views)
Re: [avian] HOw to write sql for get top 100 record in CGI perl script? [In reply to] Can't Post

I cannot answer this question because, like FishMonger, I do not know what you mean by "Top 100 records". As I said in my first post, if you mean the first 100 records, fetch 100 records and stop.
Good Luck,
Bill


wickedxter
User

Nov 7, 2013, 6:39 PM

Post #6 of 6 (1236 views)
Re: [BillKSmith] HOw to write sql for get top 100 record in CGI perl script? [In reply to] Can't Post

i've done something close to what you want before

u need to lookin to the sql: ORDER BY and LIMIT

EX:

select * from table where money>=500000 order by asc limit=100


(This post was edited by wickedxter on Nov 7, 2013, 6:41 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives