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
 Need help with a custom table please

Author  Topic 

bentham7246
Starting Member

6 Posts

Posted - 2014-11-05 : 04:51:29

Hi all,

Very new to SQL programming so apologies if my terminology is a little off.

I need some help combining a few tables, however I'm worried that it's not even possible!! (but what do I know)

So I have 1 table that is just a list of feeds. A, B, C, D etc (15 rows in total) and each feed has other information attached to it such as Full name, location etc etc. I am only interested in the Feed column.

Each feed then has a corresponding data table which contains a list of records. Eg Feed A data is contained in TableA, Feed B data is contains in TableB and so on.

Basically what I need is a combined table that shows the list of Feeds in the 1st Column ( So A, B, C, D…..) and then a second column which counts the records from each separate data table corresponding to that feed.

So the end result would look something like this:

Feed------No of Records
A----------4 (from TableA)
B----------7 (from TableB)
C----------8 (from TableC)
D----------1 (from TableD)

Possible?

Any help on sql code would be much appreciated.

Thanks

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2014-11-05 : 06:29:30
See if this works

select feed, count(*) as no_of_records from TableA group by feed
union all
select feed, count(*) as no_of_records from TableB group by feed
union all
select feed, count(*) as no_of_records from TableC group by feed
union all
select feed, count(*) as no_of_records from TableD group by feed


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

bentham7246
Starting Member

6 Posts

Posted - 2014-11-07 : 05:46:06
Thanks :-)
Go to Top of Page
   

- Advertisement -