Click here to Skip to main content
15,899,126 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Description Table

ID Text Control_ID

1 hi 17

1 hhh 17

Time table

Id Time Control_ID

1 67 17

1 12 17


controlTable

control_id

17

18

19

need to display:

hi 67 17

hhh 12 17


I have 3 tables as above and I want combined records.
Posted
Comments
The Manoj Kumar 19-Nov-13 15:25pm    
Did you try anything? Hint: Use joins and use distinct :).
Sumit Kumar Singh India 19-Nov-13 22:58pm    
SELECT d.[Text], t.[time], d.control_id
FROM DescriptionTable AS d INNER JOIN TimeTable AS t ON d.control_id = t.control_id

I have try above query but its showing below result set

hi 67 17
hhh 67 17
hi 12 17
hhh 12 17
Maciej Los 20-Nov-13 14:32pm    
Please, see my answer after update.

Try this:
SQL
SELECT d.[Text], t.[time], d.control_id
FROM DescriptionTable AS d INNER JOIN TimeTable AS t ON d.control_id = t.control_id


SQL
DECLARE @DescriptionTable TABLE (ID INT, aText VARCHAR(30), Control_ID INT)

INSERT INTO @DescriptionTable (ID, aText, Control_ID)
SELECT ID, aText, Control_ID
FROM (
    SELECT 1 As ID, 'hi' AS aText, 17  AS Control_ID
    UNION ALL
    SELECT 2 As ID, 'hhh' AS aText, 17 AS Control_ID ) AS T



DECLARE @Timetable TABLE (Id INT, aTime INT, Control_ID INT)

INSERT INTO @Timetable (Id, aTime, Control_ID )
SELECT 1 AS Id, 67 AS [Time], 17 AS Control_ID UNION ALL
SELECT 2, 12, 17

SELECT d.aText, t.aTime, d.control_id
FROM @DescriptionTable AS d INNER JOIN @TimeTable AS t ON d.ID  = t.ID



For further information about joining data, please see: Visual Representation of SQL Joins[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900