Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6636927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:14:53+00:00 2026-05-25T23:14:53+00:00

See the SQL query below – it allow you to search the Shop by

  • 0

See the SQL query below – it allow you to search the Shop by Postcode, Company Name or Town (location)… On the frontend website there will be only one search textbox without dropdown search type.

It will only show the result if shop_options.live is equal to 1 and depending which day shop is open: O_Hour.weekday = '5' (Friday).

If I search by S_D.postcode (for example: S_D.postcode = 'L14') it will then find L14 from shop_delivery_area table and then display list of shops from that postcode.

SELECT distinct S.*, S.company, S.street, S.town FROM shop as S
    JOIN shop_delivery_area as S_D on S_D.shopID = S.shopID
    JOIN shop_options on shop_options.shopID = S.shopID
    JOIN shop_opening_hours as O_Hour on O_Hour.shopID  = S.shopID
WHERE (S_D.postcode = 'Liverpool'  OR S.company LIKE 'Liverpool' OR S.town LIKE 'Liverpool') 
AND shop_options.live = '1' AND O_Hour.weekday = '5' 
    ORDER BY O_Hour.opentime

The query does work but its very slow. Almost a second to get the result. How to improve the performance faster?

Edit: Fixed SQL query.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:14:54+00:00Added an answer on May 25, 2026 at 11:14 pm

    If you need to keep the predicates i.e.

    S_D.postcode = 'Liverpool'  OR S.company LIKE 'Liverpool' OR S.town LIKE 'Liverpool'
    

    Then consider adding indexes on the same columns. So:

    ALTER TABLE shop_delivery_area ADD KEY `sda_idx1` (`postcode`);
    ALTER TABLE shop ADD KEY `shop_idx1` (`company`);
    ALTER TABLE shop ADD KEY `shop_idx2` (`town`);
    

    One other point is about fuzzy searching. If you can replace the ‘LIKE’ with an ‘=’ then you’ll see a speed increase. There’s not much point using ‘LIKE’ with no fuzzy searching though i.e. LIKE ‘Liverpool’. Use either LIKE ‘%Liverpool%’ or = ‘Liverpool’. So either use:

        S_D.postcode = 'Liverpool'  OR S.company LIKE '%Liverpool%' OR S.town LIKE '%Liverpool%'
    

    or

        S_D.postcode = 'Liverpool'  OR S.company = 'Liverpool' OR S.town = 'Liverpool'
    

    If you use the latter and create the indexes then your query should run just fine!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

See the SQL Query below, it seem to be working well. It allow me
See the SQL query below, it count the number of Yes and No between
See the SQL query below, it count the total records that match with numbers
How to see this format hh:mm from hh:mm:ss in SQL Server 2008 query ?
I'm using the below query to return results from a table using Full-Text-Search. In
I have a SQL Query as below: SELECT urban_appr, urban_in, rural_appr, rural_in, ground_appr, ground_in
I have written an SQL Query that brings the result in below format ResourceName
See below 2 versions of code and SQL it produces. I want to load
Problem solved: Thanks guys, see my answer below. I have a website running in
I can see SQL Server Compact Destination under Data Flow Destinations, but I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.