Sample Header Ad - 728x90

Query to select cards and transactions

0 votes
1 answer
751 views
I have some trouble with a query definition. My database is about operations in a bank and I want to show the card numbers which were used in transactions at all ATMs. This is how my tables DDL:
CREATE TABLE Cards(
	card_id INT PRIMARY KEY IDENTITY(1,1),
	number VARCHAR(25),
	CVV CHAR(3),
	bankAccount_id INT REFERENCES BankAccount(account_id)
);
CREATE TABLE Transactions(
	transaction_id INT PRIMARY KEY IDENTITY(1,1),
	ATM_id INT REFERENCES ATM(id),
	card_number INT REFERENCES Cards(card_id),
	sum_money INT,
	transaction_time DATETIME
);
And I tried below query:
SELECT *
FROM Cards C
WHERE C.card_id = ALL (SELECT *
						FROM Transactions T
						WHERE T.card_number = C.card_id
						)
And it doesn't work since I used card_id on both sides. Can somebody help me, please?
Asked by hackermanwow (71 rep)
Dec 23, 2020, 04:07 PM
Last activity: Dec 23, 2020, 09:52 PM