Tharun Masarp
Tharun Masarp

Reputation: 1

How to retrieve foreign key column data using primary key column of a table

Let's say I have a table store with columns store_id (PK) and store_address, and I have another table store_manager with columns manager_id (Pk), pwd, store_id (fk to store.store_id).

I want to get store_id from store_manager using manager_id and pwd

Upvotes: 0

Views: 1804

Answers (1)

kapil
kapil

Reputation: 409

If you are just looking for the store_id from the table store_manager. you need a simple select statement

SELECT store_id from store_manager where manager_id = YOUR_VALUE;

If you are looking to get the data related to store using the foreign key use the joins.

SELECT STORE.store_address, store_manager.store_id from store_manager, store
where store_manager.manager_id = YOUR_VALUE
AND store_manager.store_id = store.store_id;

Let me know if you are looking for more details.

Upvotes: 1

Related Questions