mysql - how do i get a list starting with a letter and continue with next letters?
SELECT contact_id, last_name FROM contacts
WHERE last_name like 'B%' ORDER BY last_name limit 0, 250
returns only the B's.
what I need is to return 250 rows starting with the first Bs. If there are fewer than 250 Bs, then I need to get the followin开发者_开发百科g Cs, Ds etc.
Caveat: This comparison works on SQL Server, I'm assuming it does on MySQL as well, but can't test it.
SELECT contact_id, last_name
FROM contacts
WHERE last_name > 'B'
ORDER BY last_name
LIMIT 0, 250
Will exclude records deemed alphanumerically 'less than' B.
Most DB Engines will compare text such that this will work...
SELECT contact_id, last_name FROM contacts
WHERE last_name > 'B' ORDER BY last_name limit 0, 250
you can OR your where statements
SELECT contact_id, last_name FROM contacts
WHERE last_name like 'B%' or last_name like 'C%' or last_name like 'D%' ORDER BY last_name limit 0, 250
and so on...
What about not like 'A%' ? ( so you will drop As and Bs will be first ) or Regexp ?
精彩评论