3

This is an example of my table:

|..id.|.class...|.group....|..name....|
|..5..|....1....|.....A....|....XX....|
|.19..|....1....|.....B....|....XX....|
|.12..|....2....|.....A....|....XX....|
|.28..|....2....|.....B....|....XX....|
|..8..|....3....|.....A....|....XX....|
|.50..|....3....|.....B....|....XX....|

It has about 30 rows per class and group. What I'm trying to do is to fetch all data after the row | 12 | 2 | A | XX |. Can't just state "where class > 2" since there are still some rows with class and group 2A that I need to be in the select.

Is there a way to do that, from SELECT or maybe a Fetch() argument in PHP & Mysql

Thanks!

4
  • Yes, there are about 30 rows with the same class and group. Let's say I need to start to fetch or select in the middle of that class and group. Commented Jun 6, 2013 at 20:14
  • how do you know then? If there's no explicitly discriminating data you have to go manually excluding a bunch of ids. Is there any valid alphabetic exclusion on the names? I mean, within the 2-A group, do you want to start from a given name ascending/descending? Commented Jun 6, 2013 at 20:15
  • The name, yes, I know the specific id and name from where I want to start the selection. id=12 class=2 group='A' name='Marcus', and the selection is "order by class,group,name asc". Commented Jun 6, 2013 at 20:26
  • how many different groups are there? Commented Jun 6, 2013 at 20:32

3 Answers 3

1

Try this:

SELECT * FROM `table`
WHERE
    CONCAT(`CLASS`, `GROUP`, `NAME`) >= '2AMarcus'
Sign up to request clarification or add additional context in comments.

8 Comments

I've tried it, but, doesn't that second part need to be in a subquery or something?
As long as no names in this class and group start with a letter before 'M' this could work.
Shure it shoulds, but can't get any rows, I think it has something to do with the CONCAT within the same query... may be.
could you show an extract of your database please? (a real one)
'Finally make it work by removing the ' in concat, "concat(class,group,name)>'2AMarcus'. Thanks a lot guys; StaticVoid, Sebas & Friko, I really appreciate it.
|
1

It looks like you need some work on normalizing tables, out of sql sentences. If you need the rows after Class 2 Group A Name Marcus, it says to me that something occur in real life from that point in the time, an event, so, i would add a new column for timestamp or for another data for that event, and then back to sql sentences and use that new column for the apropiate SELECT / WHERE.

1 Comment

Indeed, there's a new column on the table, and need this query to set their values in a php loopin. Timestamp would be a useful reference. Thx
0

Select all ids and loop through them creating a comma-delimited list in PHP of the ids after 12 is found. Then do your select where id in ().

Or

Create the list of ids to exclude until 12 is found. Then do select where id not in ().

1 Comment

Ok, that sounds as a workin solution. 'Will try the 2nd one, since there are about 70 ids before id=12, whereas after id12 there are about 300 more. =/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.