Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
Not applicable

how to find top 1

how to find top first  value in the column through scripting.

I have a sql query i need to implement this query through script in qlikview.

i had already loaded these fields from excel.

SELECT TOP 1 [new value] FROM status_history

WHERE [defect id] = new.[defect id].

7 Replies

Re: how to find top 1

If you have read from excel you must use Load instead of select (this one loads from database)

so use this expression:

First 1 LOAD * resident mytable;

Re: how to find top 1

Hi

Try like this

First 1 Load NewValue;

SELECT [new value] FROM status_history

WHERE [defect id] = 34;

or

You can use directly like this

SQL SELECT TOP 1 [new value] FROM status_history

WHERE [defect id] = new.[defect id];

but new.[defect id] is referring any other table???

Re: how to find top 1

You can directly use SQL query as

SQL SELECT TOP 1 [new value] FROM status_history

WHERE [defect id] = new.[defect id].

sasikanth
Valued Contributor III

Re: how to find top 1

HI

Try some thing like this

SELECT TOP 1 *   FROM status_history

WHERE [defect id] = new.[defect id].

you can replace 1 with any number

amit_saini
Honored Contributor III

Re: how to find top 1

Hi Nishika,

Try this:

SELECT TOP 1 column_name FROM table_name
ORDER BY column_name ASC;

Thanks,

AS

Not applicable

Re: how to find top 1

The error is odbc connection failed .

I had already loaded the column from my excel sheet and i need to perform this sql query in qlikview by implementing it through script I don't want to connect it with database  from where i fetched the sql query.

pradeepreddy
Valued Contributor II

Re: how to find top 1

If u want to fetch  Top N values

1)  Irrespective of order,

     SELECT TOP N Column_Name FROM status_history

      WHERE [defect id] = new.[defect id]

2) In Order, i.e  Max N or Min N records,

     SELECT TOP N Column_Name FROM status_history

      WHERE [defect id] = new.[defect id]

     Order by Column_Name ASC/DESC

Community Browser