473,396 Members | 1,987 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,396 software developers and data experts.

query two or more tables

46
Hello everybody. I am in a mess. I am unable to retrieve data from three tables. Please advise.

I have 3 tables in access. None of them has a primary key.

Table 1
Passenger surname
Passenger other name
flight number

Table 2
Passenger surname
Passenger Other name
Offence
tablename


Table 3
Passenger surname
Passenger Other name
Offence
tablename

I understand that there should be a primary key for each table, but there is no such key in any table.

Table 1 is dynamic, meaning that there could be a number of flight landing in a day

Table 2 and 3 are static

I wish to pass a query so that I could generate a list containing the surname and other information of passengers matching either table 1 or table 2

The expected result may appear like this

Surname | Oname | Offence | Tablename
Tom | J | x | Table1
Tom | J | y | Table2
Tom | w | r | Table1
Arnaud | J | y | Table2
Brown | d | s | Table1
Brown | d | y | Table2

Please help me out.......
Sep 18 '08 #1
6 1684
shweta123
692 Expert 512MB
Hi,

Can you please more clear about your doubt?
Because here as you have specified Table2 and Table3 are containing same fields. Have you taken it with any purpose?
Table 1
Passenger surname
Passenger other name
flight number

Table 2
Passenger surname
Passenger Other name
Offence
tablename


Table 3
Passenger surname
Passenger Other name
Offence
tablename

I understand that there should be a primary key for each table, but there is no such key in any table.

Table 1 is dynamic, meaning that there could be a number of flight landing in a day

Table 2 and 3 are static

I wish to pass a query so that I could generate a list containing the surname and other information of passengers matching either table 1 or table 2

The expected result may appear like this

Surname | Oname | Offence | Tablename
Tom | J | x | Table1
Tom | J | y | Table2
Tom | w | r | Table1
Arnaud | J | y | Table2
Brown | d | s | Table1
Brown | d | y | Table2
Sep 18 '08 #2
giandeo
46
Hi
Yes.
Table 2 and table 3 contains the same fields but different data from different sources. In fact, they are watchlists through which data from table1 will be filtered.I have included a source (tablename) to differentiate between the tables.

If the surname of a passenger from table1 matches the surname in table2 and also matches the surname from table3 then, I wish to get two records with same surname.

If the surname of a passenger from table1 matches the surname in table2 or table3 ONLY then, I wish to get one records with same surname.

Frankly speaking, I am trying to help someone developing an application to track risky travellers. Suggestions from anyone would be most welcome.

I am using ASP and MS Access to do this little trick.

I have given it a try. Here are the codes:
Expand|Select|Wrap|Line Numbers
  1. set adorst = server.createobject("ADODB.recordset")
  2.  
  3. adorst.Open "SELECT table1.sname, table1.oname, table2.offence, table3.offence, table2.source, table3.source from table1, table2, table3 where table1.sname=table2.sname or table1.sname=table3.sname order by table1.sname", adocon
  4.  
  5. do while not adorst.eof
  6.       response.write adorst("sname")
  7.       response.write adorst("oname")
  8.       response.write adorst("offence")
  9.       response.write adorst("source")
  10.  
  11.                   response.write("</br>")
  12. adorst.movenext
  13. loop
  14.  
  15. %>
Kindly note that the code does not work!!! The system is stuck and no response. I need to reboot the pc again.

Please advise .....
Sep 19 '08 #3
jhardman
3,406 Expert 2GB
Hi
Yes.
Table 2 and table 3 contains the same fields but different data from different sources. In fact, they are watchlists through which data from table1 will be filtered.I have included a source (tablename) to differentiate between the tables.

If the surname of a passenger from table1 matches the surname in table2 and also matches the surname from table3 then, I wish to get two records with same surname.

If the surname of a passenger from table1 matches the surname in table2 or table3 ONLY then, I wish to get one records with same surname.

Frankly speaking, I am trying to help someone developing an application to track risky travellers. Suggestions from anyone would be most welcome.

I am using ASP and MS Access to do this little trick.

I have given it a try. Here are the codes:

Kindly note that the code does not work!!! The system is stuck and no response. I need to reboot the pc again.

Please advise .....
I don't think you can do that in one query unless you got really creative with your sql - maybe you could post in a db forum. Adding a primary key wouldn't necessarily help with this step (although I would highly recommend that you add one before you get much further).

Jared
Sep 19 '08 #4
JamieHowarth0
533 Expert 512MB
Hi guys,

Two words - UNION ALL. Allows you to join the resultsets of two tables with matching schemas together to create one resultset.

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM Table1 INNER JOIN
  2. (SELECT * FROM Table2
  3. UNION ALL
  4. SELECT * FROM Table3) AS JoinedData
  5. ON Table1.Surname = JoinedData.Surname
  6.  
In this example, we do the UNION ALL on the two identical tables (data that comes from different sources). Then, we join on Table1 (flight details) to our newly created resultset on an individual's surname (and optionally firstname, but I left this bit out).

Hope this helps.

medicineworker
Sep 19 '08 #5
giandeo
46
Hi guys,

Two words - UNION ALL. Allows you to join the resultsets of two tables with matching schemas together to create one resultset.

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM Table1 INNER JOIN
  2. (SELECT * FROM Table2
  3. UNION ALL
  4. SELECT * FROM Table3) AS JoinedData
  5. ON Table1.Surname = JoinedData.Surname
  6.  
In this example, we do the UNION ALL on the two identical tables (data that comes from different sources). Then, we join on Table1 (flight details) to our newly created resultset on an individual's surname (and optionally firstname, but I left this bit out).

Hope this helps.

medicineworker
Yes. The solution works fine. Thank you so much ......
Oct 2 '08 #6
JamieHowarth0
533 Expert 512MB
You're welcome :-)

medicineworker
Oct 4 '08 #7

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

Similar topics

0
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me...
7
by: Phin | last post by:
I need your HELP! I've seen all the posts on using Crystal Reports within vs.net (vb.net) and changing a SQL query at runtime. When I tried to pass in a dataset into the crystal report at...
3
by: Jonathan | last post by:
Hi all! For a match schedule I would like to find all possible combinations of teams playing home and away (without teams playing to themselves of course). I now the simple version works...
6
by: Umar Farooq | last post by:
Hello all, Please bear with the long explanation of my scenario. As I'm relatively new to the query world, I like to write my queries using the visual toos such as the "View" option in SQL...
1
by: hmiller | last post by:
I'm sorry to populate the server with yet another question about linking multiple tables and queries, howerver I have not been able to find the right criteria. My problem. I am trying to...
3
by: Hyphessobricon | last post by:
Hallo, Indeed, a count of a query with a group by function gives more records than there are and so for-next structures don't function. How is this to be mended. Anyone? Everyone in fact....
5
by: jonceramic | last post by:
Hi All, I started developing in Access, and people took notice and so we're starting to migrate into our corporate's bigger Oracle system. I'll still be using my developed Access front ends,...
3
by: KNN | last post by:
Hi I have some tables with hidden attribute set to 1. In the query desgn view , I do not see these tables as expected. But, If I choose the query wizard to create a new query, then i do see...
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...
2
by: existential.philosophy | last post by:
This is a new problem for me: I have some queries that open very slowly in design view. My benchmark query takes about 20 minutes to open in design view. That same query takes about 20 minutes...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.