[Postgresql] Combining queries?
I need to fetch data from two tables - organizationinfo and temp_organizationinfo,
Code:
select ctrl_no, organization_name, domain_name from organizationinfo, temp_organizationinfo where ctrl_no = '1420'; But I get the error above, how do I fetch from these two tables in one query??? another problem is that both tables have the same column names, so doing 'organizationinfo.ctrl_no' results in having me too choose between the two... but I want both tables. Anyone help? :( |
SQL "join"
You need to perform a SQL "join" on your two tables. For example:
Code:
select a.ctrl_no, organization_name, domain_name [list=1][*]Gives the aliases 'a' and 'b' to tabkes 'organizationinfo' and 'temp_organizationinfo'[*]Relates ("joins") table 'organizationinfo' to 'temp_organizationinfo" via the field 'ctrl_no'[*]Further restricts the query to only those records where 'ctrl_no' in 'organization_name' equals 1420[*]Prints out the fields ctrl_no, organization_name and domain_name for each record that matches your search criteria[/list=1] I qualified "a.ctrl_no", to distinguish it from "ctrl_no" in the other table (temp_organizationinfo). If some of the other columns match, you'll have to qualify those column names, too. If the same data is in both tables, I'm not sure why you'd even need a join: just do a simple "select" from one table or the other (but not both at the same time). Finally, if you're planning on doing much database work, I'd *highly* recommend the following book: "SQL Queries for Mere Mortals", Michael J. Hernandez and John L. Viescas Hope that helps .. PSM |
Well, both tables has different data.. but they're the same in their columns.
Quote:
|
Quote:
Code:
Table "person1" Code:
+----------+---------+ For the example above, your query would be: Code:
SELECT name, country |
All times are GMT -5. The time now is 03:33 PM. |