Results 1 to 3 of 3

Thread: Correct mysql query?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    From the UK
    Posts
    422

    Question Correct mysql query?

    Hi, I have 3 tables - 'categories' just stores the name of my clients categories. 'business' stores info about businesses and 'businesscategories' has the id of businesses and categories - so in other words a business could have any number of categories.

    If I wanted to find only those businesses where category=$clients-choice AND businessname=$whatever, what is the correct mysql query for that?

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Correct mysql query?

    probably something like this:
    Code:
    select * 
    from categories c 
    inner join businesscategories bc on c.id = bc.categoryid
    inner join businesses b on bc.businessid = b.id
    where c.categoryname = $selection and b.name = $otherselection
    Although as I think about it, shouldn't filter based on text like that... unless you're allowing wildcards in the selection... but if they are limited to only what's in the db...


    Code:
    select * 
    from businesses b
    inner join businesscategories bc on b.id = bc.businessid 
    where c.id = $selection and b.id = $businessidselection
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    From the UK
    Posts
    422

    Re: Correct mysql query?

    Thank you sir, I will try that

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width