Results 1 to 6 of 6

Thread: Using a wildcard on a column

  1. #1
    Join Date
    Apr 2006
    Location
    Amsterdam
    Posts
    350
    Thanks
    20
    Thanked 11 Times in 11 Posts

    Default Using a wildcard on a column

    Hi Guys,

    I want to use the % wildcard on a query to match some phrases from one table to a column on another table . But I am having doubts whether I am actually doing the right thing here.

    This my query:
    SELECT name, phonenumber, address, streetname FROM `wb_stores`, `wb_store-street` WHERE wb_store-street.streetname LIKE wb_stores.%address%

    There are two tables:
    wb_stores
    Code:
    +--------+-------------+--------+--------------------+
    | ID     |   shopname  |  tel   |       address      |
    +--------+-------------+--------+--------------------+
    | 10000  | Tesco       | 205587 |  main street 55a   |
    | 10001  | Halfords    | 208790 |  north Boulevard 4 |
    | 10002  | T-Mobile    | 204221 |  north Boulevard 8 |
    | 10003  | H & M       | 215889 |  main street 43c   |
    | 10004  | McDonald's  | 205952 |  main street 43b   |
    | 10005  | Jack & Jones| 207285 |  kingfisher road 2 |
    | 10006  | Diesel      | 202085 |  Hayne road 22f    |
    +--------+-------------+--------+--------------------+
    wb_store-street
    Code:
    +--------------------+
    |     streetname     |
    +--------------------+
    |  main street       |
    |  kingfisher road   |
    |  north Boulevard   |
    |  Hayne road        |
    |  main street       |
    |  Conway street     |
    |  Borough road      |
    |  Price street      |
    |  Holland road      |
    |  Hamilton square   |
    +--------------------+
    I need to match the street name (from table: wb_store-street)with the street name part in de address (from table: wb_stores). Any clue's ?
    Last edited by Rappie; 13th December 2009 at 11:04 PM.

  2. #2
    Join Date
    Feb 2004
    Posts
    4,877
    Thanks
    2
    Thanked 134 Times in 113 Posts

    Default

    Are there any identifiers in the wb_store-street table? Or rather what are you trying to gain from that table?
    Warren Ashcroft
    Red Fox UK Limited - Pioneers in Internet Technology
    http://www.redfoxuk.com
    w.ashcroft [at] redfoxuk.com

    NOTE: Forum Private Messaging should not be used to contact staff with support queries.

  3. #3
    Join Date
    Apr 2006
    Location
    Amsterdam
    Posts
    350
    Thanks
    20
    Thanked 11 Times in 11 Posts

    Default

    The wb_store-street table doesn't have any other columns. The result I am after is a list of all shops ordered and categorized by street name. For example:

    - main street
    Tesco
    H & M
    McDonald's

    - north Boulevard
    Halfords
    T-Mobile

  4. #4
    Join Date
    Feb 2004
    Posts
    4,877
    Thanks
    2
    Thanked 134 Times in 113 Posts

    Default

    Off the top of my head I can only think of using a sub query which may not be the best/most efficient way:

    Code:
    SELECT *, (SELECT streetname FROM wb_store-street WHERE wb_stores.address LIKE '%' + wb_store-street.streetname + '%') AS streetname FROM wb_stores
    Warren Ashcroft
    Red Fox UK Limited - Pioneers in Internet Technology
    http://www.redfoxuk.com
    w.ashcroft [at] redfoxuk.com

    NOTE: Forum Private Messaging should not be used to contact staff with support queries.

  5. #5
    Join Date
    Dec 2008
    Posts
    14
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default

    It would be much easier to split the street and number into seperate columns:

    wb_stores
    Code:
    +--------+-------------+--------+--------------------+----------------+
    | ID     |   shopname  |  tel   |       street       |     number     |
    +--------+-------------+--------+--------------------+----------------+
    | 10000  | Tesco       | 205587 |  main street       |  55a           |
    | 10001  | Halfords    | 208790 |  north Boulevard   |  4             |
    | 10002  | T-Mobile    | 204221 |  north Boulevard   |  8             |
    | 10003  | H & M       | 215889 |  main street       |  43c           |
    | 10004  | McDonald's  | 205952 |  main street       |  43b           |
    | 10005  | Jack & Jones| 207285 |  kingfisher road   |  2             |
    | 10006  | Diesel      | 202085 |  Hayne road        |  22f           |
    +--------+-------------+--------+--------------------+----------------+
    Then, with your streets table...

    Code:
    SELECT *
    FROM wb_stores
    INNER JOIN wb_stores-street
        ON wb_stores.street = wb_stores-street.streetname
    WHERE wb_stores-street.streetname = [VARIABLEGOESHERE]
    Now, I can't actually look at the word street without it looking totally wrong...

  6. #6
    Join Date
    Apr 2005
    Location
    Haslemere, Surrey, UK
    Posts
    338
    Thanks
    5
    Thanked 3 Times in 3 Posts

    Default

    You could try
    SELECT name, phonenumber, address, streetname
    FROM wb_stores
    inner join wb_store-street on left(wb_stores.address ,len(wb_store-street.streetname )) = wb_store-street.streetname
    In an ideal world you would have your wb_store-street table linked to you wb_store table by a recordid to avoid duplication of address streets.

    However, this SQL matches the wb_store-street.streetname to the wb_stores.address, only matching up to the length of the wb_store-street.streetname, thereby ignoring the address street number.
    Alastair - WOWD



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •