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

A single query between two tables without link on its fields

mariusseven
P: 19
SELECT
SUM (fieldname) AS T_Withheld
,SUM (fieldname) AS G_Income

,SUM(fieldname) + SUM (fieldname) + SUM(fieldname) + SUM(fieldname) AS Premium
,SUM (fieldname) - fieldnameC - (SUM(fieldname) + SUM (fieldname) + SUM(fieldname) + SUM(fieldname)) AS T_Income
,fieldnameA
,fieldnameB

FROM tablename A
GROUP
BY fieldnameA
,fieldnameB
,fieldnamec

and


select fieldnameA, fieldnameB, fieldnameC, fieldnameD

from tablename B

Really need ideas
Mar 28 '08 #1
Share this Question
Share on Google+
13 Replies


code green
Expert 100+
P: 1,726
By no link do you mean there is no common field between the two tables?
If that is the case what is wrong with two select statements?
Mar 28 '08 #2

P: 32
poe
You don't have to have a link to join tables. There should be something similar between these two tables to join on, correct?

I think it would help if you gave full, correct SQL statement(s).
Mar 28 '08 #3

ck9663
Expert 2.5K+
P: 2,878
How would you know which record pairs with what record?

-- CK
Mar 28 '08 #4

mariusseven
P: 19
I want to make only one query because i'll be using it to create a .ttx file of crystal reports to be used in vb6.




By no link do you mean there is no common field between the two tables?
If that is the case what is wrong with two select statements?
Mar 29 '08 #5

mariusseven
P: 19
The data i need are from two tables that have nothing in common..is it impossible to create a single query on both of their fields?


How would you know which record pairs with what record?

-- CK
Mar 29 '08 #6

ck9663
Expert 2.5K+
P: 2,878
Not impossible.

Would you mind posting sample data on both tables an how you want it joined?

-- CK
Mar 29 '08 #7

mariusseven
P: 19
Sorry for the late relpy..
here is the sample of tables....

table 1
Name......Cont1..... Cont2...... Cont3.....Cont4

Name1 .....100 ......200 .........300.........400
Name2......500...... 600..........700.........800
Name3 ......900......1000........1100 ......1200

table 2
Code ......%Cont ......ContA......ContIN ..... ContFL
Code1 ...... 0 .............. 0 ........ 0 ............ 100000
Code2. ...... 5 ........... 500.........10000........30000
Code3. .......10........ ..1000........30000 ....... 70000
Code4.........15...........1500........70000 ...... .14000
Apr 2 '08 #8

ck9663
Expert 2.5K+
P: 2,878
How do you want this joined? How would the joined table look?

-- CK
Apr 2 '08 #9

mariusseven
P: 19
i just want the query of both tables, i don't want them to join or merge. i want to query them using a single query with filters.
Its like i want to compare the total values of the first table cont to the range of the values of the second.


How do you want this joined? How would the joined table look?

-- CK
Apr 2 '08 #10

code green
Expert 100+
P: 1,726
just want the query of both tables, i don't want them to join or merge. i want to query them using a single query with filters
A JOIN doesn't merge tables,
it merges results from the tables in to one recordset.
The tables are unaffected.
You want to run a query collecting results from both tables which is normally a JOIN query,
but requires common data in at least one field of each table.
Without this you could try a UNION which is two SELECT statements with UNION between.
The number of fields in each SELECT must match
Apr 2 '08 #11

ck9663
Expert 2.5K+
P: 2,878
I'll give him the benefit of the doubt ;)

Based on your example, how would you do it in a pseudo-code?

-- CK
Apr 2 '08 #12

mariusseven
P: 19
The code i have made was the one that i have posted first, but i have no idea on how to connect the two...


I'll give him the benefit of the doubt ;)

Based on your example, how would you do it in a pseudo-code?

-- CK
Apr 8 '08 #13

code green
Expert 100+
P: 1,726
We seem to be going around in circles.
The code i have made was the one that i have posted first, but i have no idea on how to connect the two
By connect I have to assume you mean JOIN.
Unfortunately YOU need to tell us how you want the tables JOINed because we do not know what you are trying to achieve.
Its like i want to compare the total values of the first table cont to the range of the values of the second
How are you hoping to do this?
Apr 8 '08 #14

Post your reply

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