Hello all.
I have a Jet SQL question:
I'm trying to write a query based on these 2 tables:
table1:
A: B:
1 1
2 1
3 1
4 1
5 1
1 2
2 2
3 2
4 2
5 2
table2:
C: D:
1 1
2 1
3 1
4 1
5 1
1 2
2 2
3 2
4 2
5 2
Now the query needs to show all the combinations of all the fields: - SELECT table1.A, table1.B, table2.C, table2.D
-
FROM table1, table2;
but without the rows where A = C and without the rows where both of these conditions occur on the same row: A = C + 1, B<>D.
Please help me to combine this query without using UNION, if possible
Thank you, I appreciate your time.
Try: - SELECT Table1.A, Table2.C, Table1.B, Table2.D
-
FROM Table1, Table2
-
WHERE (((Table1.A)<>[Table2].[C] And (Table1.A)<>[Table2].[C]+1) AND ((Table1.B)=[Table2].[D]));
OUTPUT: -
A C B D
-
5 1 1 1
-
4 1 1 1
-
3 1 1 1
-
5 2 1 1
-
4 2 1 1
-
1 2 1 1
-
5 3 1 1
-
2 3 1 1
-
1 3 1 1
-
3 4 1 1
-
2 4 1 1
-
1 4 1 1
-
4 5 1 1
-
3 5 1 1
-
2 5 1 1
-
1 5 1 1
-
5 1 2 2
-
4 1 2 2
-
3 1 2 2
-
5 2 2 2
-
4 2 2 2
-
1 2 2 2
-
5 3 2 2
-
2 3 2 2
-
1 3 2 2
-
3 4 2 2
-
2 4 2 2
-
1 4 2 2
-
4 5 2 2
-
3 5 2 2
-
2 5 2 2
-
1 5 2 2
-
4 1801 Try: - SELECT Table1.A, Table2.C, Table1.B, Table2.D
-
FROM Table1, Table2
-
WHERE (((Table1.A)<>[Table2].[C] And (Table1.A)<>[Table2].[C]+1) AND ((Table1.B)=[Table2].[D]));
OUTPUT: -
A C B D
-
5 1 1 1
-
4 1 1 1
-
3 1 1 1
-
5 2 1 1
-
4 2 1 1
-
1 2 1 1
-
5 3 1 1
-
2 3 1 1
-
1 3 1 1
-
3 4 1 1
-
2 4 1 1
-
1 4 1 1
-
4 5 1 1
-
3 5 1 1
-
2 5 1 1
-
1 5 1 1
-
5 1 2 2
-
4 1 2 2
-
3 1 2 2
-
5 2 2 2
-
4 2 2 2
-
1 2 2 2
-
5 3 2 2
-
2 3 2 2
-
1 3 2 2
-
3 4 2 2
-
2 4 2 2
-
1 4 2 2
-
4 5 2 2
-
3 5 2 2
-
2 5 2 2
-
1 5 2 2
-
Works well, thanks!
I guess you can't build everything with Access query builder.
Actually, this Query you can (both Tables Shown but not Joined): -
Field: A B C D
-
-----------------------------------------------------------------------------------
-
Table: Table 1 Table1 Table2 Table2
-
-----------------------------------------------------------------------------------
-
Criteria: <>[Table2].[C] And <>[Table2].[C]+1 [Table2].[D]
-
-----------------------------------------------------------------------------------
-
It's just easier to show SQL rather than showing the query designer.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: DotNetJunkies User |
last post by:
I am trying to build a xPath Query to use on SelectNodes function in VB.net
The data I want to search is by
MemberCity = O'Fallon
My xPath Query is
xPathQuery = "Matched"
The problem is...
|
by: Akinia |
last post by:
Hi every body
I've a little problem with my query, I can't figure it out. I've three
tables:
Table A (EmployeNr, Date, Code)
Table B (EmployeNr, Date, Code) Which is an historic of Table A...
|
by: MLH |
last post by:
I have a table (tblCorrespondence) holding records with fields like
, , , , , ,
, etc...
About a dozen 's are defined and I often use queries to
extract records of a given . That's pretty easy....
|
by: stockblaster |
last post by:
Hello
I am using stored procedure with sql 2005 (with Visual studio 2005)
I have two tables .. TABLE1 And TABLE2
>From TABLE1 i need to retrive the OrderID's of the 4 most top rows. so
i...
|
by: jardar.maatje |
last post by:
I am logging scientific data. For this a normal relationship database
is not idéal but I am going to try it.
I have basically three tables like:
datarecord:
* idx - integer
* time - datetime...
|
by: kalindi05 |
last post by:
Hello everyone,
Please help me revise this query to make it work. I don't know much about update query so I will need some help with it. Thanks,
update encounter
set mergedpayment =...
|
by: kalindi05 |
last post by:
Hello everyone,
Please help me revise this query to make it work. I don't know much about update query so I will need some help with it. Thanks,
update encounter
set mergedpayment =...
|
by: Robert |
last post by:
I need to set up a query that will pick out records for the current winter
season.
I.e., each season runs from October 1 until March 31. The catch is, the year
can't be hard coded. So, if the...
|
by: Slower Than You |
last post by:
Well, I think it's complex anyway -- you might not :)
TableDef:
CREATE TABLE CustTransactions (
TransactionKey int IDENTITY(1,1) NOT NULL,
CustomerID int,
AmountSpent float,
CustSelected bit...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |