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

  • SEARCH
  • Home
  • 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 9236011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:11:14+00:00 2026-06-18T07:11:14+00:00

I have 3 tables that are set up like so: Quotes Table Stores Table

  • 0

I have 3 tables that are set up like so:

Quotes Table                        Stores Table    
id  store_id    date_submitted      store_number    code
1   15          1/29/13 23:13       15          ANT
2   16          1/30/13 7:47        16          MAT

Leads Table 
code    user_name
MAT         User1
ANT         User2

What I want to be able to do is have the query return all the values in the quotes table, and then the code values from the Stores table, and the user_name from the leads table. I would like it to look something like this:

id  store_id    date_submitted  code    user_name
1   15          1/29/13 23:13   ANT User2
2   16          1/30/13 7:47    MAT User1

I have the following query that I wrote:

SELECT id, store_id, date_submitted, code, user_name FROM quotes q, stores s, leads l WHERE CONCAT('%', q.store_id, '%') LIKE CONCAT('%', s.store_number, '%') AND s.code=l.code AND date_submitted > "2013-01-01 00:00:00" AND date_submitted < "2013-01-31 23:59:59" GROUP BY q.id

The problem I’m running into, is the database isn’t matching the code to the correct store_id.

I’m not sure what I’m doing wrong here, I have looked at a couple of SO posts, and googled for it to no avail.

Any assistance would be appreciated.

  • 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-06-18T07:11:15+00:00Added an answer on June 18, 2026 at 7:11 am

    Well, why are you using wildcards (%) to join store_id with store_number?, can’t you use an exact match?. Also, just for clarity, you should use explicit JOINs:

    SELECT id, store_id, date_submitted, code, user_name 
    FROM quotes q
    INNER JOIN stores s
        ON q.store_id = s.store_number
    INNER JOIN leads l 
        ON s.code=l.code 
    WHERE date_submitted > "2013-01-01 00:00:00" 
    AND date_submitted < "2013-01-31 23:59:59" 
    GROUP BY q.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bill of materials table that is set up like this: item
I have an SQL database with a set of tables that have Unique Id's.
We have a set of tables and views that merely store some config data
If you have a set of tables in the database that strictly consist of
I have a table that displays a set of data. But when I try
I have a table that containts a set of columns one of it is
I have a table that has three different date columns, so I set each
I have a page a query that will set a table to 0 or
I have a MySQL table & fields that are all set to UTF-8. The
I have a table X with column Y, that contains text like this: Click

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.