Solved

How do I combine multiple recordsets in query?

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

628 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