Hi Everyone am very new to SQL and self teaching myself until I can take a SQL class hopefully this spring. Came across this example and having been trying to figure it out.

I've made two tables.
The first table (X) has columns X1 and X2.
The second table (Y) has columns X and D.
Both X1 and X2 have a foreign key constraint referring to column X in table Y.
Write a query to determine all X1,X2 such that X1 and X2 have different values for D.

I've got the two tables but am not sure how to write the query. Any help will be appreciated. This is what I have so far.


query="
CREATE TABLE X
(ID INTEGER PRIMARY KEY),
X1 CHAR(20),
X2 CHAR(20),
FOREIGN KEY (X1) REFERENCES Y(X)
FOREIGN KEY (X2) REFERENCES Y(X)
;
CREATE TABLE Y
(ID INTEGER PRIMARY KEY),
X CHAR(20),
D CHAR(20),
;


"
sqldf(query)