473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Query across two tables

Please help me with this query..
I have two tables..One is customer details table and another transaction details table.
The customer details table has all the details of internal customers..
like following
Cust_id Accnt_id
1 001
2 002
and so on..
The transaction details table has details like
TxnId Acnt_id Type benAcnt DrAcntId
12 001 dep 001 235
13 001 dep 001 002
14 001 with 456 001
15 001 with 003 845
And so on..
What i want is the list of all account ids that 001 has transacted with irrespective of type..Here 001,002,003 are internal customers while 235,456,845 are external customers whose details are not available in customer details table..So i want the list of such external customers transacted with customer 001. Some thing like following,
Acnt_id ExternalAcnt_id
001 235
001 456
001 845 . Please help in forming query for this..
Aug 31 '07 #1
3 1274
azimmer
200 Expert 100+
Please help me with this query..
I have two tables..One is customer details table and another transaction details table.
The customer details table has all the details of internal customers..
like following
Cust_id Accnt_id
1 001
2 002
and so on..
The transaction details table has details like
TxnId Acnt_id Type benAcnt DrAcntId
12 001 dep 001 235
13 001 dep 001 002
14 001 with 456 001
15 001 with 003 845
And so on..
What i want is the list of all account ids that 001 has transacted with irrespective of type..Here 001,002,003 are internal customers while 235,456,845 are external customers whose details are not available in customer details table..So i want the list of such external customers transacted with customer 001. Some thing like following,
Acnt_id ExternalAcnt_id
001 235
001 456
001 845 . Please help in forming query for this..
Expand|Select|Wrap|Line Numbers
  1. select X.*
  2. from (
  3.     select Acnt_id, benAcnt as ExternalAcnt_id
  4.     from TRANSACTIONSTABLE
  5.     where benAcnt>='200'
  6.  
  7.     union 
  8.  
  9.    select Acnt_id, DrAcntId as ExternalAcnt_id
  10.    from TRANSACTIONSTABLE
  11.    where DrAcntId>='200') as X
  12. where Acnt_id = '001'
  13.  
Aug 31 '07 #2
Expand|Select|Wrap|Line Numbers
  1. select X.*
  2. from (
  3.     select Acnt_id, benAcnt as ExternalAcnt_id
  4.     from TRANSACTIONSTABLE
  5.     where benAcnt>='200'
  6.  
  7.     union 
  8.  
  9.    select Acnt_id, DrAcntId as ExternalAcnt_id
  10.    from TRANSACTIONSTABLE
  11.    where DrAcntId>='200') as X
  12. where Acnt_id = '001'
  13.  

Its not always that external account id is greater than 200..It can have any id..only thing is that the external ids are not present in customer details table.
Aug 31 '07 #3
azimmer
200 Expert 100+
Its not always that external account id is greater than 200..It can have any id..only thing is that the external ids are not present in customer details table.
OK, here it goes:
Expand|Select|Wrap|Line Numbers
  1. select X.*
  2. from (
  3.     select Acnt_id, benAcnt as ExternalAcnt_id
  4.     from TRANSACTIONSTABLE
  5.     where benAcnt not in (select Acnt_id from CUSTOMERS)
  6.  
  7.     union 
  8.  
  9.     select Acnt_id, DrAcntId as ExternalAcnt_id
  10.     from TRANSACTIONSTABLE
  11.     where DrAcntId not in (select Acnt_id from CUSTOMERS)) as X
  12. where Acnt_id = '001'
  13.  
Aug 31 '07 #4

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

Similar topics

8
by: Rigga | last post by:
Hi, I am new to mysql and need help on how to join tables. I have a database which contains 4 tables, the main table contains information by date order and the other 3 contain data also in date...
3
by: Jason | last post by:
I will explain (or at least try to) first and then give an example after. I need to append a number of rows from several tables into one master table. Unfortunately there are certain columns...
3
by: mel_palmeruk | last post by:
Hi I'm new to MySQL and am wanting to be connected to the MySQL server and query across diffrent db's. To my understanding a different db in MySQL is the same as a schema in Oracle. Am I correct...
1
by: John Brajkovich | last post by:
I have 10 tables that are identical in structure. They contain a location code, an employee id for that location and a score. In all of these tables a location code/employee id combanation uniquely...
11
by: deko | last post by:
If I release a new version of my mbd (in mde format) and users want to upgrade - how do they migrate their data? For example, if the original was released as data1.mde and then I release...
7
by: RLN | last post by:
Re: Access 2000 I have three history tables. Each table contains 3 years worth of data. All three tables have a date field in them (and autonum field). Each table has the potential to contain...
3
by: mkjets | last post by:
I have worked for hours on trying to find a solution and have not figured it out. I am working in Access 2003. I need to create a query that takes values from 1 table and displays them in...
6
by: gerbski | last post by:
Hi all, I am relatively new to ADO, but up to now I got things working the way I wanted. But now I've run into somethng really annoying. I am working in MS Access. I am using an Access...
6
by: jsacrey | last post by:
Hey everybody, got a secnario for ya that I need a bit of help with. Access 97 using linked tables from an SQL Server 2000 machine. I've created a simple query using two tables joined by one...
5
by: bobh | last post by:
Hi All, Is there a difference in preformance between the two; TblNme has 36 fields across a record a query that selects all fields and the report only uses 75% of the fields, ie; Select...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.