Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

MySQL Problem

  • 20-08-2008 2:11pm
    #1
    Registered Users, Registered Users 2 Posts: 9,225 ✭✭✭


    right so i have a database with US state names, lng, lat, city names and zip codes. I am trying to search it by city name but when i do i get an empty set - the only way i get a return on any search is by Zip Code. any ideas what i can do to get around this?


Comments

  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    right so i have a database with US state names, lng, lat, city names and zip codes. I am trying to search it by city name but when i do i get an empty set - the only way i get a return on any search is by Zip Code. any ideas what i can do to get around this?
    You shouldn't need to "get around this". Post your code, it's just a problem with your query I'd say. No reason why you should get an empty set if the data exists.


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    Can you give an example of a query you're running as well as the structure of the table(s)?


  • Registered Users, Registered Users 2 Posts: 9,225 ✭✭✭Chardee MacDennis


    so table is as follows:

    ZIPCODE INT
    STATEABV VARCHAR(5)
    LAT VARCHAR(30)
    LNG VARCHAR(30)
    CITY VARCHAR(30)
    STATE VARCHAR(30)

    This works:
    SELECT * FROM `USCITIESNEW` WHERE `ZIPCODE`=94704
    

    and i get
    94704  	 CA  	37.868575  	-122.25855  	 Berkeley  	 California
    

    for this
    SELECT *  FROM `USCITIESNEW` WHERE `CITY` LIKE 'Berkeley'
    

    and this
    SELECT *  FROM `USCITIESNEW` WHERE `CITY` = 'Berkeley'
    

    get this
    MySQL returned an empty result set (i.e. zero rows). (Query took 0.0005 sec)


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Well since it's not an error, are you positive that query should return a result? Is it spelled correctly in your query and in the database?


  • Registered Users, Registered Users 2 Posts: 9,225 ✭✭✭Chardee MacDennis


    i copied the text 'Berkeley' from the first result!!


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    Could be a whitespace issue.

    what about
    SELECT *  FROM `USCITIESNEW` WHERE `CITY` LIKE '%Berkeley%'
    


  • Registered Users, Registered Users 2 Posts: 9,225 ✭✭✭Chardee MacDennis


    seamus wrote: »
    Could be a whitespace issue.

    what about
    SELECT *  FROM `USCITIESNEW` WHERE `CITY` LIKE '%Berkeley%'
    

    BAM! thats got it thanks! is there anyway to rectify this issue, or do i have to search with the % from now on?


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    I would consider this to be a form of data corruption - probably caused by the initial import of data into the database (if there was one).

    Basically, there is whitespace (spaces, tabs, CRLFs) at one or both ends of the city name. You can use the % to search in future, but it's not ideal - your best approach would be to try clean up the data corruption.


  • Registered Users, Registered Users 2 Posts: 9,225 ✭✭✭Chardee MacDennis


    seamus wrote: »
    I would consider this to be a form of data corruption - probably caused by the initial import of data into the database (if there was one).

    Basically, there is whitespace (spaces, tabs, CRLFs) at one or both ends of the city name. You can use the % to search in future, but it's not ideal - your best approach would be to try clean up the data corruption.

    well there are over 33,000 records and it was a pain to import them, think i may just leave it. thanks for all the help!


  • Closed Accounts Posts: 35 dkell


    A problem you might run into using % is that it's a wildcard; so if you've got two similar records (e.g. 'Berkeley' and 'West Berkeley') you're going to both results returned.

    As you can't clean the data, have you try using the Trim function to chop any whitespace when doing the query?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 9,225 ✭✭✭Chardee MacDennis


    dkell wrote: »
    A problem you might run into using % is that it's a wildcard; so if you've got two similar records (e.g. 'Berkeley' and 'West Berkeley') you're going to both results returned.

    As you can't clean the data, have you try using the Trim function to chop any whitespace when doing the query?

    yup using trim thanks!


  • Registered Users, Registered Users 2 Posts: 3,889 ✭✭✭cgarvey


    Use trim to update the database then .. make your queries slightly quicker from then on


Advertisement