Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help with UNION

Author  Topic 

engcanada
Starting Member

39 Posts

Posted - 2011-12-30 : 18:24:43
Can someone please help me combine these 2 select queries that have nothing in common. I am assuming UNION caluse is it?
Please make sure OBDER BY in both queries are not ignored:

SELECT top 20 ForumTopic.IdTopic, ForumTopic.Topic, ForumTopic.idTeacher, Forum.teacher, Forum.Feedback, Forum.dateforum, Forum.idfeedback, Forum.allow FROM Forum INNER JOIN ForumTopic ON Forum.IdTopic = ForumTopic.IdTopic where allowtopic=1 order by dateforum desc


SELECT top 20 title, salary, moneda, idjob, country, dateposted, details from SCHOOL where status='0' order by dateposted desc

Thank you

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-12-30 : 19:08:36
You can't combine them as they have a different number of columns and have different data types. While you can get around this via various hacks, what is the purpose of combining them? Do this at your application layer and not in T-SQL.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

engcanada
Starting Member

39 Posts

Posted - 2011-12-30 : 19:22:58
I am trying to pick the most recent record regardless of the TABLES and, have it come on up in a RSS feed application.
Go to Top of Page

engcanada
Starting Member

39 Posts

Posted - 2011-12-30 : 19:25:45
I don t want to create 2 seperate feeds.

cheers
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-12-30 : 19:51:16
Show us how the unioning would work. Provide sample data from both tables and the expected output for the sample data. We need that to help since they can't be unioned as is.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

whatamouth
Starting Member

16 Posts

Posted - 2012-01-03 : 04:12:30
use full outer join instead

Neil Matias
neilmatias@yahoo.com
Go to Top of Page
   

- Advertisement -