-1

I have two tables

Property and Photo

Photo table has PropertyId FK column which assigning to Property table.

I have stored procedure which returns data from property table, now I want to modify this st. procedure to return photos data together with property data in a single st. procedure query. How to do this?

CREATE PROCEDURE GetAllData
AS
SELECT * 
FROM dbo.Property
GO
user1765862
  • 13,635
  • 28
  • 115
  • 220

2 Answers2

0

You join the 2 tables by an Id column.

CREATE PROCEDURE GetAllData

AS

SELECT * FROM dbo.Property prop
INNER JOIN dbo.Photo photo ON prop.PropertyId = photo.PropertyId 

Another post about JOIN

Community
  • 1
  • 1
shammelburg
  • 6,974
  • 7
  • 26
  • 34
0

Try below code.

CREATE PROCEDURE GetAllData
AS
SELECT * 
FROM dbo.Photo p inner join dbo.Property pr
on p.PropertyId = pr.PropertyId 
GO
Felix Pamittan
  • 31,544
  • 7
  • 41
  • 67