0

This might be a very simple, but I couldnt make it to work.Hope I get some help.

I have a select statement which returns the follow data

Id  Name  Phone  msg     File
1    A    null   null     f1

another select statement

Id     Name   Phone   msg      File
NULL   NULL    123   nothing     f1
NULL   NULL    156   nothing1    f1

How do I merge the above as

Id     Name   Phone   msg      File
1       A      123   nothing     f1
1       A      156   nothing1    f1

I tried using max and group by on File. Any help is appreciated.

Thanks in advance

3
  • What field are you linking to? Some sample data and your Select statements would be very helpful. Commented Jan 9, 2013 at 22:44
  • I'm confused, are you just trying to join on the File column and select columns from two tables? Commented Jan 9, 2013 at 22:45
  • Could you provide the SELECTs? What database engine we are talking about? Commented Jan 9, 2013 at 22:46

2 Answers 2

3
Select s1.ID,s1.Name,s2.Phone,s2.msg,s2.File
from s1
Join s2 on s1.file=s2.file
Sign up to request clarification or add additional context in comments.

Comments

0

Query:

SQLFIDDLEExample

SELECT t1.[Id],
       t1.[Name],
       t2.[Phone],
       t2.[msg],
       t2.[File]
FROM Table1 t1
JOIN Table2 t2 ON t1.[File]=t2.[File]

Result:

| ID | NAME | PHONE |      MSG | FILE |
---------------------------------------
|  1 |    A |   123 |  nothing |   f1 |
|  1 |    A |   156 | nothing1 |   f1 |

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.