Author |
Topic |
sartis
Starting Member
11 Posts |
Posted - 2014-05-08 : 10:19:44
|
Hello, I want to select data from 2 tables in my database that are not related to each other. the first table is a news table and the second is a players table. When I output the data on my site I want the data from both tables to be mixed together based on dates....for instance:The first item may be a new player and the next 3 could be news items, etc just based on the date. I hope this makes sense. I was trying a join but since they are not related i was not having success. I hope I'm not over thinking this and missed something really easy. Thanks. |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2014-05-08 : 10:51:27
|
maybe a union ?select col from newsunion allselect col from players KH[spoiler]Time is always against us[/spoiler] |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-05-09 : 05:18:55
|
depends on what all details you want to show. If metadata (columns) required is same you can use UNION ALL as Tan suggested. Otherwise you need to retrieve them as seprate queries. In any case if you can give us an example of sample data and what you need from it that might help.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
sartis
Starting Member
11 Posts |
Posted - 2014-05-09 : 10:03:50
|
ok, Here are the columns for the two tables ......the first table is called news:news_idnews_datenews_blurbnews_titleSecond table is called players:player_idplayer_fnameplayer_lnameplayer_unameplayer_pwdplayer_locplayer_commentsplayer_date_addedplayer_fullnameuser_last_login_dtuser_last_logout_dtuser_ip_addresslogin_counterplayer_emailplayer_photoplayer_sinceplayer_handplayer_heightplayer_weightacademy_levelparent_matchI want to create news feed for new things on the site. I have it in 2 different queries right now. I want 1 query that would intermingle the data. I need to select the following columns:News:news_date - date fieldnews_blurb - varchar(max)news_title - varchar(500)Players:player_fullname - computed column from player_fname and player_lnameplayer_since - dateplayer_date_added - dateplayer_photo - varchar(500)I want to output the data by news_date and player_date_added. I did try the union all and I was getting the following error.I hope this helps. In this screen shot I would want Zoey Clements moved up under the top 2 news items because her data added is 5/8. |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2014-05-09 : 11:01:46
|
can you show us your Query ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
sartis
Starting Member
11 Posts |
Posted - 2014-05-09 : 11:15:23
|
I tried the union suggestion: select news_title,news_blurb,news_date from news union all select player_fullname,player_fname,player_date_added from playersbut I'm getting this error:PLAYER_FULLNAME is undefined in GET_ALL_ACTIVITY.so it output 1 news item fine but is erring on the first player output......the query will get more involved once I get the basics down. (I will only select like on 2 weeks back, etc. ) |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2014-05-09 : 20:26:23
|
what is "GET_ALL_ACTIVITY" " i don't see it in your query KH[spoiler]Time is always against us[/spoiler] |
 |
|
sartis
Starting Member
11 Posts |
Posted - 2014-05-09 : 23:10:44
|
it is the name of my query.... |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2014-05-09 : 23:34:18
|
quote: Originally posted by sartis it is the name of my query....
are you using Microsoft SQL Server ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
sartis
Starting Member
11 Posts |
Posted - 2014-05-09 : 23:48:40
|
yes and Coldfusion for server side scripting. |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2014-05-10 : 00:35:41
|
This site is on Microsoft SQL Server. There might not be many that are familiar with coldfusion. Please post in a coldfusion discussion site KH[spoiler]Time is always against us[/spoiler] |
 |
|
sartis
Starting Member
11 Posts |
Posted - 2014-05-10 : 08:15:11
|
I think this is a sql issue, that is why I posted it here. |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2014-05-11 : 21:40:33
|
It is not that we don't want to help you but but the error message does not make sense to me based on my knowledge on Microsoft SQL Server. You will be better and faster help in the appropriate site.What do you think ? If my BMW won't start and can i bring it to a Mercedes service center ? It is still a CAR right ? I probably can get a general diagnostic (is your battery dead ? Did you press the start button ? etc) and might not be able to solve or replace any fault partsWell, here is the general diagnostic we can provide.Few things to check for UNION query1. run individual SELECT statement, make sure it is correct2. make sure the no of select columns in all the query are the same3. make sure the data type of the columns are the same4. if your DB is case sensitive collation, make sure you specify the column name exactly (case wise) as in the schema KH[spoiler]Time is always against us[/spoiler] |
 |
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2014-05-12 : 05:18:43
|
omg teach u got bm d??? |
 |
|
sartis
Starting Member
11 Posts |
Posted - 2014-05-12 : 09:18:12
|
so when I run the follow sql command select news_title,news_blurb,news_date from news union all select player_fullname,player_fname,player_date_added from playersin management studio I understand why I'm getting PLAYER_FULLNAME is undefined in GET_ALL_ACTIVITY. the only columns returned from the query are news_title,news_blurb,news_date. But it puts the data from the player select clause under these columns.....I'm sure that is the default behavior of a union, correct?? Here's a screenshot:[url]http://connexzone.artisdesigns.com/union.jpg[/url] |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2014-05-13 : 05:21:36
|
yes KH[spoiler]Time is always against us[/spoiler] |
 |
|
|