Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I combine multiple recordsets in query?

Posted on 2008-10-06
4
Medium Priority
?
669 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 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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.
Suggested Courses

782 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