sql query for union or join?

Posted by Chandru_ra under Sql Server on 7/8/2011 | Points: 10 | Views : 1242 | Status : [Member] | Replies : 6
Dear all,

i have using two tables one table name forums another one response. u have post in any forums top in the list and any respone also top list.

but dont repeat the forums title. display in one time only.. another person post in forums table top in the list.

what query use for this problem and post any example for this

Advance Thanks to all

chandru


Responses

Posted by: Ndebata on: 7/8/2011 [Member] Starter | Points: 25

Up
0
Down
Lets say there are two tables caled Forum and Response
Forum

ForumID Title PostedBy
1 What is LINQ xyz
3 Some Topic ABc

Response

ResponseIDForumID Description PostedBy
2 1 LINQ1... akska
3 1 LinQ response 2 hdjhfdj
4 3 some answer sdsdsd
5 1 again linq answer hsshs


Then if you want all your responses to be sorted under that forum with the latest on the top then

Select ForumID,0 as ResponseID, Title, PostedBy,0 IsResponse from Forum

UNION ALL
Select ForumID,ResponseID,[Description] as Title, PostedBy,1 IsResponse from Response
Order by ForumID,IsResponse, ResponseID desc


Chandru_ra, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sriramnandha on: 5/20/2012 [Member] Starter | Points: 25

Up
0
Down
SELECT * FROM TABLE1
UNIONALL
SELECT * FROM TABLE2

JOINS;

SELECT * FROM TABLE1
INNER JOIN TABLE2
ON TABLE1.COLUMNNAME=TABLE2.COLUMNNAME

REGARDS


sriram

Chandru_ra, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajay.Kalol on: 5/21/2012 [Member] Starter | Points: 25

Up
0
Down
SELECT Id,Name FROM Table1
UNION
SELECT Id,Name FROM Table 2

SELECT Id,Name FROM Table1
UNION ALL
SELECT Id,Name FROM Table 2

Note that two queries must contain same fields in Union and union all Operation

Differance :

In UNION ALL,
Both table data including duplicate data are included in result
in UNION
only Distinct Data from both table are included in result

Ajay
ajaypatelfromsanthal.blogspot.in

Chandru_ra, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajay.Kalol on: 6/4/2012 [Member] Starter | Points: 25

Up
0
Down
Hey Chandru_ra,

If you find any solution from this please Mark the answer as accepted

Ajay
ajaypatelfromsanthal.blogspot.in

Chandru_ra, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jasminej on: 6/4/2012 [Member] Starter | Points: 25

Up
0
Down
@Ajay.Kalol

I think your definition for Union and Union All is Wrong!

Kindly check once before submit!

Chandru_ra, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajay.Kalol on: 6/4/2012 [Member] Starter | Points: 25

Up
0
Down
Sorry It was writing Mistake.


Ajay
ajaypatelfromsanthal.blogspot.in

Chandru_ra, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response