473,385 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

selecting top 10 entries

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.

Expand|Select|Wrap|Line Numbers
  1. select top 10 * from t_security where segmentcode in(
  2. 'AIM','AIM3','AIMI','AMSM','ASQ1','ASQ2','ASX1','ASX2','ASXN','CIBB','CNVE','CRNR','CRTR','CSEQ','CSET','CSQX',
  3. 'CWNR','CWNU','CWTR','CWTU','EQS','ETCS','ETF2','ETFS','GILT','INSD','IOB','IOBU','IRSQ','IRSU','ITBB','ITBU',
  4. 'ITR','LVSD','MIBB','MISC','MISL','MSEQ','MSET','MSQX','MSTM','NSTS','ODTT','PSNR','PSTR','RSET','RSTM','SET1',
  5. 'SET2','SET3','SSMM','SSMU','SSQ3','SSX3','SSX4','STBS','STMM','TC1E','TC1M','TC1O','TCAE','TCAM','TCAO','TEST',
  6. 'XIBB','XSEQ','XSET','XSTM','ZA01','ZA02','ZA03','ZA04','ZA11','ZA21','ZA22','ZA24'
  7. )
  8.  
Can anyone pls help
Sep 12 '07 #1
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
Sep 12 '07 #2
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.
Sep 12 '07 #3
pbmods
5,821 Expert 4TB
Heya, Greg.

You're looking for the ORDER BY clause.
Sep 12 '07 #4
amitpatel66
2,367 Expert 2GB
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.

Expand|Select|Wrap|Line Numbers
  1. select top 10 * from t_security where segmentcode in(
  2. 'AIM','AIM3','AIMI','AMSM','ASQ1','ASQ2','ASX1','ASX2','ASXN','CIBB','CNVE','CRNR','CRTR','CSEQ','CSET','CSQX',
  3. 'CWNR','CWNU','CWTR','CWTU','EQS','ETCS','ETF2','ETFS','GILT','INSD','IOB','IOBU','IRSQ','IRSU','ITBB','ITBU',
  4. 'ITR','LVSD','MIBB','MISC','MISL','MSEQ','MSET','MSQX','MSTM','NSTS','ODTT','PSNR','PSTR','RSET','RSTM','SET1',
  5. 'SET2','SET3','SSMM','SSMU','SSQ3','SSX3','SSX4','STBS','STMM','TC1E','TC1M','TC1O','TCAE','TCAM','TCAO','TEST',
  6. 'XIBB','XSEQ','XSET','XSTM','ZA01','ZA02','ZA03','ZA04','ZA11','ZA21','ZA22','ZA24'
  7. )
  8.  
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:

Expand|Select|Wrap|Line Numbers
  1. SELECT E.* FROM
  2. (SELECT e.*,ROW_NUMBER() OVER(PARTITION BY e.segmentcode ORDER BY e.segmentcode) rn from t_security e) E
  3. WHERE rn BETWEEN 1 AND 10
  4. ORDER BY E.segmentcode
  5.  
Sep 13 '07 #5
pbmods
5,821 Expert 4TB
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....
Sep 13 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
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...
1
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...
3
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...
3
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...
1
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...
3
by: mgreenway | last post by:
aut_id txt_head mem_body yon_approved 1 y 2 n 3 y 4 ...
1
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...
5
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....
1
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...
0
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$) { } ...
0
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...
0
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
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...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.