I have a simple database with one table and 2 columns (id,company). These statements do not work: SELECT * FROM names where company = '%A' PHP: SELECT * FROM names where company LIKE '%A' PHP: But the query,s below pull everything from the table including names begining withe the letter A SELECT * FROM names where company <= '%A' PHP: SELECT * FROM names where company NOT LIKE '%A' PHP: I have around 50 companies starting with the letter A Any ideas please ?
Hi Here is a shortcut way to get all the company having name starting with 'A' SELECT * FROM names where len(company,1) = 'A'
besides you did a little mistake to fetch starting with 'A' the condition should be 'A%' rather than '%A'. '%A' will fetch all the records that last letter is A. You could read sql wild issue here http://www.techonthenet.com/sql/like.php
Not able to execute the query Either the table doesnot exist or a wrong query. Query is : SELECT * FROM names where len(company,1) = 'A' Resolved ** Looking at the data in the database, the problem was when I uploaded the company names I had a blank space at the begining and ending of each word.
Then you could do two things. 1. SELECT * FROM names where len(company,2) = ' A' 2. SELECT * FROM names where len(ltrim(company),1) = 'A' for pemanently removing spaces from both sites do the following update names set company=rtrim(ltrim(company))