mabus Posted October 23, 2008 Share Posted October 23, 2008 Hello, I have mysql query problems that I can't seem to figure out yet. the scenario involves two tables, and the objective is to be able come up with an uput that combines the reults from the two related tables. here's the scenario. ViewType (Id, Name) < --- this is a lookup table Table B (Id, ProfileId, Date, ViewTypeId) <-- ViewTypeId field is a foreign key associated with ViewTypeTable Now, what I am aimign for is to come up with results that summarizes according the month and the view type. So the table should have these columsn "Date", "Number of Views", "ViewType 1 view" , "View Type 2 view" Please share your ideas to me. Thanks in advance... Quote Link to comment https://forums.phpfreaks.com/topic/129741-need-help-with-mysql-query/ Share on other sites More sharing options...
fenway Posted October 23, 2008 Share Posted October 23, 2008 Why not join the tables? Quote Link to comment https://forums.phpfreaks.com/topic/129741-need-help-with-mysql-query/#findComment-673227 Share on other sites More sharing options...
mabus Posted October 27, 2008 Author Share Posted October 27, 2008 hhhmm..joins are too expensive, os I'm putting that as a last resort Quote Link to comment https://forums.phpfreaks.com/topic/129741-need-help-with-mysql-query/#findComment-675315 Share on other sites More sharing options...
corbin Posted October 27, 2008 Share Posted October 27, 2008 I would consider joins your best resort. It's either joins or 23890128901890752374890123748901273589012734890723847128903758901237 queries. Quote Link to comment https://forums.phpfreaks.com/topic/129741-need-help-with-mysql-query/#findComment-675323 Share on other sites More sharing options...
mabus Posted October 27, 2008 Author Share Posted October 27, 2008 ahahahhahaha.. thats fun.. hhhmm ..I'm not too good at joins. can anyone give me a sample query on this? thanks in advance guys, I really appreciate it Quote Link to comment https://forums.phpfreaks.com/topic/129741-need-help-with-mysql-query/#findComment-675342 Share on other sites More sharing options...
Barand Posted October 27, 2008 Share Posted October 27, 2008 SELECT DATE_FORMAT(b.Date, '%Y %m) as yearmonth, COUNT(*) as totalviews, GROUP_CONCAT(t.Name) as views FROM TableB b INNER JOIN ViewType t ON b.ViewTypeId = t.Id GROUP BY yearmonth Quote Link to comment https://forums.phpfreaks.com/topic/129741-need-help-with-mysql-query/#findComment-675444 Share on other sites More sharing options...
mabus Posted October 27, 2008 Author Share Posted October 27, 2008 thanks for that dude. I appreciate it.. Quote Link to comment https://forums.phpfreaks.com/topic/129741-need-help-with-mysql-query/#findComment-675529 Share on other sites More sharing options...
mabus Posted October 28, 2008 Author Share Posted October 28, 2008 This one works dude. The "yearmonth" , and "totalviews" columns that it produces are correct , except for the lasts ones. What I'd like to have is to have different columns for the view types too. Got any query suggestions on how I can I achieve that? again, thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/129741-need-help-with-mysql-query/#findComment-676253 Share on other sites More sharing options...
Barand Posted October 28, 2008 Share Posted October 28, 2008 http://www.phpfreaks.com/forums/index.php/topic,222873.msg1025547.html#msg1025547 Quote Link to comment https://forums.phpfreaks.com/topic/129741-need-help-with-mysql-query/#findComment-676370 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.