Hi,
I'm trying to select the top 10 entries from a table per a variable. At present the below query brings up only 10 entries but I want 10 entries per segmentcode. -
select top 10 * from t_security where segmentcode in(
-
'AIM','AIM3','AIMI','AMSM','ASQ1','ASQ2','ASX1','ASX2','ASXN','CIBB','CNVE','CRNR','CRTR','CSEQ','CSET','CSQX',
-
'CWNR','CWNU','CWTR','CWTU','EQS','ETCS','ETF2','ETFS','GILT','INSD','IOB','IOBU','IRSQ','IRSU','ITBB','ITBU',
-
'ITR','LVSD','MIBB','MISC','MISL','MSEQ','MSET','MSQX','MSTM','NSTS','ODTT','PSNR','PSTR','RSET','RSTM','SET1',
-
'SET2','SET3','SSMM','SSMU','SSQ3','SSX3','SSX4','STBS','STMM','TC1E','TC1M','TC1O','TCAE','TCAM','TCAO','TEST',
-
'XIBB','XSEQ','XSET','XSTM','ZA01','ZA02','ZA03','ZA04','ZA11','ZA21','ZA22','ZA24'
-
)
-
Can anyone pls help
5 2026 Atli 5,058
Expert 4TB
Hi Greg. Welcome to The Scripts!
You have posted your question in the Articles section rather than the Forum section.
I have moved it across for you.
Also, please enclose your posted code in [code] tags (See How to Ask a Question). Moderator Atli 5,058
Expert 4TB
What type of SQL are you using?
The 'TOP 10' syntax you use there does not seem to be valid in MySQL. I do remember it from Sql Server tho.
Heya, Greg.
You're looking for the ORDER BY clause.
Hi,
I'm trying to select the top 10 entries from a table per a variable. At present the below query brings up only 10 entries but I want 10 entries per segmentcode. -
select top 10 * from t_security where segmentcode in(
-
'AIM','AIM3','AIMI','AMSM','ASQ1','ASQ2','ASX1','ASX2','ASXN','CIBB','CNVE','CRNR','CRTR','CSEQ','CSET','CSQX',
-
'CWNR','CWNU','CWTR','CWTU','EQS','ETCS','ETF2','ETFS','GILT','INSD','IOB','IOBU','IRSQ','IRSU','ITBB','ITBU',
-
'ITR','LVSD','MIBB','MISC','MISL','MSEQ','MSET','MSQX','MSTM','NSTS','ODTT','PSNR','PSTR','RSET','RSTM','SET1',
-
'SET2','SET3','SSMM','SSMU','SSQ3','SSX3','SSX4','STBS','STMM','TC1E','TC1M','TC1O','TCAE','TCAM','TCAO','TEST',
-
'XIBB','XSEQ','XSET','XSTM','ZA01','ZA02','ZA03','ZA04','ZA11','ZA21','ZA22','ZA24'
-
)
-
Can anyone pls help
The below query takes two input parameters. Pass the value as 1 and 10 to get top ten records for each segment code: -
SELECT E.* FROM
-
(SELECT e.*,ROW_NUMBER() OVER(PARTITION BY e.segmentcode ORDER BY e.segmentcode) rn from t_security e) E
-
WHERE rn BETWEEN 1 AND 10
-
ORDER BY E.segmentcode
-
Heya, Patel.
I'm not sure which SQL variant you just posted, but that looks a lot like MS SQL, which won't help solve a MySQL problem....
Sign in to post your reply or Sign up for a free account.
Similar topics
by: webhigh |
last post by:
Iım not sure if this a PHP question or an MySQL question but here it goes.
I have a repeat region of a table called userid
What Iım trying to accomplish is being able to edit the record and...
|
by: Mark |
last post by:
Hi - I have a numebr of rooms, which I am making available.
table: single - has single_id and single_name
rental_single has rental_id, single_id, check_in and check_out
They are linked by...
|
by: Mark Wheadon |
last post by:
Hello,
We have a 'standard letters' type app that can produce the letter as
an XSL-FO document. We have used FOP to produce PDFs and are quite
impressed. We also need to be able to print the...
|
by: debugger |
last post by:
I have a drop down with alot of options say about 6000 cities and
districts. I need to select all options if user selects "All checkbox".
I use "on change" and a for loop to do this, but it takes a...
|
by: Nathan Sokalski |
last post by:
When testing a form of mine which uses RequiredFieldValidators that have the
Display property set to "Dynamic" the ErrorMessage property is automatically
removed when an entry is completely typed...
|
by: mgreenway |
last post by:
aut_id txt_head mem_body yon_approved
1 y
2 n
3 y
4 ...
|
by: michael.martinek |
last post by:
Greetings!
I've recently been trying to do something, which apparently looks like
it may be a little odd.. I'm not finding anything in the manuals or
anywhere on the web where something similiar...
|
by: Mahesh S |
last post by:
Hi
I would like to write a SQL select statement that would fetch rows
numbered 50 to 100.
Let me clarify, if i say "fetch first 10 rows only", it returns the
first 10 rows from the resultset....
|
by: gregelliott |
last post by:
Hi,
I'm trying to select the top 10 entries from a table per a variable. At present the below query brings up only 10 entries but I want 10 entries per segmentcode.
SELECT top 10 * FROM...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |