MySql query

Posted on 2011-10-06
Last Modified: 2012-05-12

I have three simple DB tables and I'm trying to do a couple queries which should be simple but I seem to be getting stuck.

First I have 2 Tables with 3 columns in them.

TABLE1 with Col1, Col2 and Col3

TABLE2 with Col1, Col2 and Col3

I want to know if any data in TABLE1.Col1 matches TABLE2.Col1 and if so I want to produce a list.

Next TABLE1 and TABLE2 list qty of units. TABLE3 list other information such as descriptions. So I need to look at TABLE3.Col4 match it to either TABLE1.col1 or TABLE2.col1 and check TABLE1.Col2 and/or TABLE2.Col2 to determine if there is more than X available. If there is more than X available than I need to get all data from TABLE3 and the Col2 data from TABLE1 or TABLE2.



Question by:jpldpd
    LVL 41

    Accepted Solution

    probably you're looking for joins:

    select a.*, b.*, c.*
    from table1 a
    join table2 b on a.col1 = b.col1
    join table3 c on b.col2 = c.col4

    Author Comment


    Sorry for the late response.

    Thanks for the help!!!


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Loading csv or delimited data files to MySQL database is a very common task frequently questioned about and almost every time LOAD DATA INFILE comes to the rescue. Here we will try to understand some of the very common scenarios for loading data …
    Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API ( …
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now