Solved

How do I combine multiple recordsets in query?

Posted on 2008-10-06
4
661 Views
Last Modified: 2013-12-12
How do I combine recordsets from 3 databases, using my sql.
Example
SELECT a,b,c,d,e,f,g
FROM  table1,table2
WHERE (and this is were I'm stuck) table1.a = table2.a

I have a third table here and I need to access that information. Typically the WHERE statement creates a condition that can be met. But I need to add an additional table. lets say table3 to the mix (the a field  being the common property number throughout all of my db). How do I do that and is it possible to ad an AND statement after that to allow me to create a condition to be met.
Maybe this helps:
I fill out a form that asks for a number range (lets say I pick 100).
I want to pass that variable through to the results page that will display a record that shows the results for all of the property numbers (A) that match the 100 variable.
From there I want to display all of the information for that property number(A) that is stored on the other 2 tables (one table contains information, the other contains image links).

Hope I didn't just confuse the bejeezus out of someone, but this is what I'm trying to do. Any help is greatly appreciated.
-A

0
Comment
Question by:adrake9
  • 2
  • 2
4 Comments
 
LVL 13

Accepted Solution

by:
AielloJ earned 500 total points
Comment Utility
Simply add the third table and use the AND clause to join them.  Make sure there is a corresponding row in table3 or the rows from table1 and table2 won't show up.
SELECT a,b,c,d,e,f,g

FROM  table1,table2,table3

WHERE table1.a = table2.a AND table1.a=table3.a

Open in new window

0
 
LVL 2

Author Comment

by:adrake9
Comment Utility

in the WHERE statement how do I join the 2 tables and allow for the variable being passed from the previous page? can I do this with another "AND" ? Like below. I understand this is kind of a new question, the points are all your (and thank you very much it works!). Just checking to see if my thinking is correct.

SELECT a,b,c,d,e,f,g

FROM  table1,table2,table3

WHERE table1.a = table2.a AND table1.a=table3.a AND table3.f = 100

Open in new window

0
 
LVL 2

Author Closing Comment

by:adrake9
Comment Utility
Just about the most cut & dry answer I've had to date! Thank you!
0
 
LVL 13

Expert Comment

by:AielloJ
Comment Utility
You can do it exactly as you outlined, you can string AND's on as long as you want.  You can mix AND's and OR's in a WHERE clause, and even put them in parenthesis, to control the precedence of the operators.

Check out the link below for a decent on-line tutorial:
  http://beginner-sql-tutorial.com/sql-operators.htm
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

771 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

10 Experts available now in Live!

Get 1:1 Help Now