Solved

How do I combine multiple recordsets in query?

Posted on 2008-10-06
4
663 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
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

825 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