If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Joining Two tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-28-05, 09:18
asif_8 asif_8 is offline
Registered User
 
Join Date: Jan 2005
Posts: 5
Joining Two tables

hi everyone
i have got 2 tables one is customer and the other is agents. i want to display all the firstnames and lastnames of the customers from the customer table and all the agentnames from the agents table and i wana see all data under one column

Last edited by asif_8; 01-28-05 at 10:56.
Reply With Quote
  #2 (permalink)  
Old 01-28-05, 12:06
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
It would help if you described those tables, so now we have to guess how to join those tables. My lucky guess will be that tables look like this:
Code:
CUSTOMER (cust_id, first_name, last_name, agent_id)
AGENT (agent_id, first_name, last_name)
If that's similar to your situation, you might try this query:
Code:
SELECT c.first_name ||' '||c.last_name ||' - '||
  a.first_name ||' '|| a.last_name customer_and_agent
FROM customer c, agent a
WHERE c.agent_id (+) = a.agent_id;
Concatenation shows all the data in one column, while outer join shows agents that don't have any customers.

I hope this helps ...
Reply With Quote
  #3 (permalink)  
Old 01-29-05, 01:12
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
agreed, table layouts and relationships would have been valuable information

but this sounds more like a UNION than a JOIN to me

Code:
select 'customer'                   as nametype
     , lastname ||', '|| firstname  as fullname
  from customers
union all
select 'agent   '   as nametype
     , agentname    as fullname 
  from agents
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On