Jump to content

Recommended Posts

The Database that I'm using

I got it but I don't know how to match them together:

return the MAX-n1 & MAX-n2

SELECT
    MAX(`VID`)-3 AS max1,
    MAX(`VID`)-2 AS max2
FROM `tests`
GROUP BY `SID`

return the value of the rows:
 

SELECT *

FROM `tests`

WHERE `VID`>='max1' AND `VID`<='max2'

ORDER BY `SID` ASC, `VID` ASC

the results should be like this :
 

Quote

 

Group:1

test - 3

test - 4

 

Group:2

test - 283

test - 284

 

Group:3

test - 197

test - 198

 

Group:4

test - 173

test - 174

 

Group:5

test - 117

test - 118

 

Group:6

test - 162

test - 163

 

Group:7

test - 203

test - 204

 

Group:8

test - 72

test - 73

 

Group:9

test - 126

test - 127

 

Group:10

test - 106

test - 107

 

 

Link to comment
https://forums.phpfreaks.com/topic/307588-select-between-2-rows-of-each-group/
Share on other sites

So you want all rows that are between max-3 and max-2? Use a JOIN with a subquery. But note that you need to consider the SID values if you're grouping by it.

Give that a shot and post what you have if it isn't working.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.