We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,420 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to search a mysql database by the first letter an entry starts with

What I need to do is search brand names, find all the brands that start with the letters A-E and put those under a header on my webpage. Then search F-O and then P-Z and do the same thing. How would I go about querying the database to get the brands that start with A-E and so on? Ive got a products table with a brands row to help with the query.

2
Contributors
1
Reply
3 Hours
Discussion Span
1 Year Ago
Last Updated
2
Views
Jfunch
Light Poster
27 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

There is a function called LEFT which can be used to grab the first letter of a field for comparison

example:

SELECT * FROM tblBrands WHERE LEFT(Brand,1) BETWEEN 'A' AND 'E'

etc...

Hearth
Posting Whiz
302 posts since Apr 2008
Reputation Points: 123
Solved Threads: 44
Skill Endorsements: 4

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0581 seconds using 2.66MB