Write a SQL query to join multiple tables and remove duplicate rows.
Use the provided customer, card, and transaction tables. For repeated transaction IDs, retain the most recently loaded record.
transaction_id, customer_id, customer_name, card_id, card_type, amount, and transaction_datetransaction_date descending, then transaction_id ascending| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique customer identifier |
| customer_name | VARCHAR(100) | Customer display name |
| customer_segment | VARCHAR(30) | Customer segment |
| Column | Type | Description |
|---|---|---|
| card_idPK | INT | Unique card identifier |
| customer_id | INT | Customer associated with the card |
| card_type | VARCHAR(40) | Card product type |
| card_status | VARCHAR(20) | Current card status |
| Column | Type | Description |
|---|---|---|
| transaction_record_idPK | INT | Unique ingestion record identifier |
| transaction_id | INT | Business transaction identifier |
| card_id | INT | Card used for the transaction |
| amount | DECIMAL(10,2) | Transaction amount |
| transaction_date | DATE | Date of the transaction |
| loaded_at | TIMESTAMP | Timestamp when the record was loaded |