Jump to content

Recommended Posts

Below is the query I have an it works good if I want the next lot in the table sorted by "asc" and there are no alpha characters involved.  The issue I run into is sometimes the LotNumber may have alpha characters in it.  For example, 1a, 1b, 2, 2d, 2dd, etc.

 

So if my order is 1a, 1b, 2, 2d, 2dd, 3

and $lot = 2,

the next value I want from the query below is 2d. 

 

Unfortunately, I get 3 for the next value.  Can someone show me what I'm doing wrong?  Thank you.

SELECT LotNumber, LotTitle, LotDescription, LotImage1, LotImage2, LotImage3, LotImage4, LotImage5, LotImage6 FROM `lots` WHERE LotDate='$date' and convert(LotNumber, signed)>'$lot' GROUP BY convert(LotNumber, signed) ORDER BY CAST(LotNumber AS UNSIGNED) asc LIMIT 1

Yes, I checked.  Here is what I have right now and if I have 1, 1a, 2, 3, 3a and $lot=1, I get 2.  If $lot=0, then I get 1a.  If $lot=1a, then I get a value of 3.

 

SELECT LotNumber, LotTitle, LotDescription, LotImage1, LotImage2, LotImage3, LotImage4, LotImage5, LotImage6 FROM `lots` WHERE LotDate='2010-07-15' and convert(LotNumber, signed)>'$lot' ORDER BY CAST(LotNumber AS UNSIGNED), LotNumber asc LIMIT 1,1

 

If I do this, it will give me the correct value ONLY if there is not an alpha character involved.  If I have 1, 1a, 2, 3, 3a and $lot=1, I get 2.  If $lot=0, then I get 1.  If $lot=1a, then I get a value of 2.

 

SELECT LotNumber, LotTitle, LotDescription, LotImage1, LotImage2, LotImage3, LotImage4, LotImage5, LotImage6 FROM `lots` WHERE LotDate='2010-07-15' and convert(LotNumber, signed)>'$lot' ORDER BY CAST(LotNumber AS UNSIGNED), LotNumber asc 

You are right.  I did change that.  Now here is what happens.  If I have 1, 1a, 2 and $lot=1a, I get 1a returned as a value which is incorrect.  If I have $lot=1, i get a returned value of 1a which is correct.  Thank you very much for trying to help me with this.

 

SELECT LotNumber, LotTitle, LotDescription, LotImage1, LotImage2, LotImage3, LotImage4, LotImage5, LotImage6 FROM `lots` WHERE LotDate='2010-07-15' and convert(LotNumber, signed)>='$lot' ORDER BY CAST(LotNumber AS UNSIGNED), LotNumber asc LIMIT 1,1

Well, it definitely wasn't for a lack of effort!  Now I just got to try and figure out how to explain this to my customer.  :(  If you can think of anything else, let me know.  I will post any solution that I may come across.  Thanks again for all your help.

Well, I don't think that will work for me either because it is strictly sorting by that value.  There really isn't any other factors involved.  If I have

 

LotNumber

1

2

2a

2b

3

4

 

I want "LotNumber>2a Limit 1" to be 2b.

 

What if you could split LotNumber into two columns.

 

LotNumeric, LotAlphabetic

1, null

2, null

2, a

2, b

3, null

4, null

 

(make sure numeric part is stored as numeric datatype)

 

Then sorting on these two columns

 

ORDER BY LotNumeric, LotAlphabetic

 

should yield required order.

Not a bad idea.  I would have to change a lot of stuff with my other queries that work OK, but it may work. 

 

What about this:

 

Can I use "count" somehow.  To say, count values ascending.  $lot=7 would be the 8th value in the list, give me the 9th value?  Would that work?  How could I do that?

Does this make any sense why this would work?  So far, it's working.  I'm trying to break it, but it seems to work.

 

SELECT LotNumber, LotTitle, LotDescription, LotImage1, LotImage2, LotImage3, LotImage4, LotImage5, LotImage6 FROM `lots` WHERE LotAuctionDate='2010-07-17' and convert(LotNumber, signed)>='$lot' and LotNumber>'$lot' ORDER BY CAST(LotNumber AS UNSIGNED), LotNumber asc 

 

If I have this:

 

1

1a

1b

2

3

 

if $lot=1a, the returned value will be 1b which is correct.  If $lot=2, the returned value will be 3 which is also correct.

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.