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


Views: 1690
HOw to write sql for get top 100 record in CGI perl script?

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


Views: 1687
Re: [avian] HOw to write sql for get top 100 record in CGI perl script?

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


Views: 1683
Re: [BillKSmith] HOw to write sql for get top 100 record in CGI perl script?

Hi

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

Avian


FishMonger
Veteran / Moderator

Nov 7, 2013, 8:10 AM


Views: 1681
Re: [avian] HOw to write sql for get top 100 record in CGI perl script?

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


Views: 1678
Re: [avian] HOw to write sql for get top 100 record in CGI perl script?

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


Views: 1668
Re: [BillKSmith] HOw to write sql for get top 100 record in CGI perl script?

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)