By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,404 Members | 1,873 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,404 IT Pros & Developers. It's quick & easy.

retrieve two tables in a single query

P: 10
I have to retrieve two tables which are not having any relation in a single query itself
for example
select * from memberphoto;select * from restricconfig;

if i execute this query only restricconfig table is viewed but i want both table to be retrieved simultaneously in a single query


advance thanks
kirthika
Jul 28 '07 #1
Share this Question
Share on Google+
10 Replies


Expert 100+
P: 534
If your tables have compatible structures you can use the UNION clause. Also see combining queries

Combining query results is not something people do very often, and one reason for that is that this is rarely justified.
Think again before you do this and make sure you are not working around some problem that should have been addressed either in database design, or somewhere else in the application.
Jul 29 '07 #2

Expert 100+
P: 534
thanka michaelb
but i want to retrieve two tables which has no relation and second table is having more rows than first one. and i want the result to show two tables displaying the rows of two tables separately.
pls is there any possible way. I can do this in sqlserver but i can't do it here. if any one know pls help me

thanks in advance
kirthika
kirthika, please append to existing thread rather than making a new one.
If you have any doubts about using this forum it may be helpful to review the Posting Guidelines at the top of the Forum.
Jul 30 '07 #3

P: 10
kirthika, please append to existing thread rather than making a new one.
If you have any doubts about using this forum it may be helpful to review the Posting Guidelines at the top of the Forum.
michaelb, please tell be how append to existing thread i can't understand
Aug 1 '07 #4

Expert 100+
P: 534
You just did!
I made this suggestion because your previous append was made as a brand new thread (I had to copy it into the correct thread), but this time you actually appended to the thread.

Basically there are two ways of doing that.
First, you click on the title and expand the thread, so you can see all individual messages in it.
Then, you can either
A) click on the Reply link at the bottom of an individual message,
or
B) click on the post reply link at the bottom of the entire thread.

The only difference between A and B is that with A your reply will include the quote of the message you are replying to, while with B your reply will have nothing else, only the message you typed in.
Aug 1 '07 #5

Expert 100+
P: 534
... ... ...
but i want to retrieve two tables which has no relation and second table is having more rows than first one. and i want the result to show two tables displaying the rows of two tables separately.
... ...
But this does not mean that you need to fetch the data from two tables in a single query!

Let's start with your environment:
- Are you using some kind of the client API to access the database?
- Where all this data supposed to be displayed?

For example, if you have a web application and you using PHP for the server side scripting, you can run two queries, each for a different table, save the results, then display these results in two different places (perhaps with HTML tables) on your page.
Aug 1 '07 #6

P: 10
But this does not mean that you need to fetch the data from two tables in a single query!

Let's start with your environment:
- Are you using some kind of the client API to access the database?
- Where all this data supposed to be displayed?

For example, if you have a web application and you using PHP for the server side scripting, you can run two queries, each for a different table, save the results, then display these results in two different places (perhaps with HTML tables) on your page.
i can't understand what are saying?
Aug 1 '07 #7

Expert 100+
P: 534
Just tell us more about your particular programming and application environment.
Let's start with where you are running your queries, and where and how the result of these queries should be displayed.
Aug 1 '07 #8

P: 10
Just tell us more about your particular programming and application environment.
Let's start with where you are running your queries, and where and how the result of these queries should be displayed.
I am doing my project in .net but i want retrieve data from two tables but in a single query
Expand|Select|Wrap|Line Numbers
  1. select * from table1;select * from table2;
  2.  
if i execute this query only the second table datas are retrieved but i want both table's data one after the other. This is possible in SQL Server. but it is not working in postgreSQL please help me to solve this.......

Thanks in advance,
kirthika.
Aug 28 '07 #9

Expert 100+
P: 534
I do not work with .NET, but I'd think you need to save the result of the first query, practically assign it to some variable or, object.
I'm sure .NET has an appropriate object for this, some kind of ResultSet.

And frankly it just seems wrong to string together two queries... what are you trying to achieve by doing this?
Aug 30 '07 #10

P: 1
Hi Krithika,

Did you get a soln for your query?

I too got stuck in the same problem.

Please provide me solns if any.

Thank You.
Dec 18 '07 #11

Post your reply

Sign in to post your reply or Sign up for a free account.