Solved

How do I combine multiple recordsets in query?

Posted on 2008-10-06
4
664 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 13

Accepted Solution

by:
AielloJ earned 500 total points
ID: 22653501
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
ID: 22653924

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
ID: 31503531
Just about the most cut & dry answer I've had to date! Thank you!
0
 
LVL 13

Expert Comment

by:AielloJ
ID: 22654257
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

749 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