473,395 Members | 2,222 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,395 software developers and data experts.

How to Select every 2nd row with condition 1 column has a same value

Hii all,

i have a problem to get every second row in a table with condition 1 column has a same value,

example: i have 1 table is called 'HP'
with column id,nik,hp,status_aktif

id | nik | hp | status_aktif
1 | 2010010269 | 08123456789 | 1
2 | 2010010269 | 08567891011 | 1
3 | 2010010271 | 08112347891 | 1
4 | 2010010271 | 08568391020 | 1

can anyone help me,
select 2nd row with condition 1 column has a same value with 'QUERY SELECT'
result:
2 | 2010010269 | 08567891011 | 1
4 | 2010010271 | 08568391020 | 1


Regards,
Octo
Oct 22 '10 #1
4 2094
colintis
255 100+
Should be something like this
Expand|Select|Wrap|Line Numbers
  1. SELECT id, nik, max(hp), status_aktif
  2. FROM [Your table here]
  3. GROUP BY nik, id, hp, status_aktif
Only works if:
1. you only have 2 records with the same nik
2. your 2nd hp value is bigger than the 1st one
Oct 22 '10 #2
Thanx for your reply Mr.colintis..

It's not working. all records is show in result.
1. There's many records in this table
2. It's random 'hp' value between 1st hp value and 2nd hp value
Oct 22 '10 #3
colintis
255 100+
Try this one if it can, as this is the closest one I can think of.
Expand|Select|Wrap|Line Numbers
  1. SELECT TOP 1 id, nik, hp, status_aktif
  2. FROM [Your table here]
  3. WHERE id NOT IN (SELECT TOP 1 * FROM [Your table here] GROUP BY nik)
  4. GROUP BY nik, id, hp, status_aktif
Oct 22 '10 #4
nico5038
3,080 Expert 2GB
You can use a DCount() function with in the WHERE parameter a test for nik being equal, status_aktif = 1 and hp <=.

This will add a sequence row numbering for each nik and allows you to filter for value 2.

Getting the idea ?

Nico
Oct 22 '10 #5

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

Similar topics

0
by: Amber | last post by:
There are times when you will need to highlight or otherwise modify the contents of a particular DataGrid row-column value based upon the value in the column. In this example we will select the...
2
by: Microsoft News Group | last post by:
I am trying to get a value from the MIN column in my database. I can not seem to get the IF statement to be true, even thou my debugging says the column value is 0, but it is not hitting the...
0
by: kowndinya | last post by:
Hai, I have created a program in vb6 , MSChart and it is working fine. This chart shows monthly sales values ( columncount =1) and chart type is vtChChartType2DBar my problem is, I want to add...
4
by: =?Utf-8?B?QmFidU1hbg==?= | last post by:
Hi, I have a GridView and a SqlDataSource controls on a page. The SqlDataSource object uses stored procedures to do the CRUD operations. The DataSource has three columns one of which -...
0
by: Joe Meng | last post by:
Greetings, I've seen this question asked and answered here, just not completely yet. I'm wondering how to use a column value as a table name in another query. So far it's looking like you must...
2
by: chumma | last post by:
Hi, i knew little bit about "Select MAX(col_name) from <table_name>" function using in mysql to find the largest value in a particular column. Now i want to know with the same fact i`ve to find...
10
by: TF | last post by:
Very newbie question and I hope this is the right group. I have a table on a web page which contains info about paint colors. One column contains the hex value for the color's RGB value. I want...
3
by: Manikandan | last post by:
Hi, I have table with three columns as below table name:exp No(int) name(char) refno(int) I have data as below No name refno 1 a 2 b 3 c
2
by: vinodkus | last post by:
dear sir/madam I have a problem . I have a table of field name ,roll_name, age I have to show name and roll_number in combo box list. please help me i m using it <select name=id1> <option...
0
by: sk27ahmed | last post by:
Hi Any one can show me how to access datagridview column value on column checked unchecked. I create one column in datagridview of type checkbox,and on button click i write code to select all...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.