473,386 Members | 1,835 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

SQL query help , MySQL 4.1

i have 2 tables
forumMsg forumTopic
id idTopic Text idUser Views id Topic
TopOrder
-------------------------------------- ----------------------
1 1 Hello 1 4 1 General 2
2 1 More 2 1 2 Other 1
3 2 Help 3 4
4 2 Msg.. 4 5

i need a query to see forum topics and :
who was the las user that posted and sum(Views),
ordered by TopOrder
like this:

Topic Views LastUserId
-------------------------------------
Other 9 4
General 5 2

it is for MySQL ver 4.1, anyway if somebody can tell me how to make
the query in ANSI SQL, thanks...
Alexei.
Jul 20 '05 #1
1 1550
Alexei Vladychevski wrote:
i have 2 tables
forumMsg forumTopic
id idTopic Text idUser Views id Topic
TopOrder
-------------------------------------- ----------------------
1 1 Hello 1 4 1 General 2
2 1 More 2 1 2 Other 1
3 2 Help 3 4
4 2 Msg.. 4 5

i need a query to see forum topics and :
who was the las user that posted and sum(Views),
ordered by TopOrder
like this:

Topic Views LastUserId
-------------------------------------
Other 9 4
General 5 2

it is for MySQL ver 4.1, anyway if somebody can tell me how to make
the query in ANSI SQL, thanks...


This is not tested, just a stab at the problem:

SELECT T.Topic, SUM(M1.Views) AS Views,
(SELECT M2.idUser FROM forumMsg M2 WHERE M2.id =
(SELECT MAX(M3.id) FROM forumMsg M3 WHERE M3.idTopic = T.id))
AS LastUserId
FROM forumTopic T INNER JOIN forumMsg M1 ON M1.idTopic = T.id
GROUP BY T.id
ORDER BY T.TopOrder

Regards,
Bill K.
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Doug Reese | last post by:
hello, i have what seems to me a very common operation i'm performing. i need to find the balance on an invoice. i was not having any problems until the production server was upgraded to mysql...
0
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me...
3
by: Paradigm | last post by:
I want to create a pass through query in Access to get data from a MYSQL table. I need to do this using code so that sertain aspects of the query can be changed. When I look at the SQL version of...
3
by: Paradigm | last post by:
I am using Access 2K as a front end to a MYSQL database. I am trying to run a Union query on the MYSQL database. The query is (much simplified) SELECT as ID from faxdata UNION SELECT as ID ...
0
by: Murphy | last post by:
I am currently migrating a db from SQL Server & MySQL and ? (front end yet to be decided upon) As I familiarise myself with MySQL populating tables etc can be quite clumbersome. After reading the...
6
by: sheree | last post by:
I would like to create a query where one of the columns of the queries comes from a combo list box on a form. For example, if my table has the following fields: id name interest1 interest2...
2
by: Galina | last post by:
Hello I need to get data from 4 Oracle tables and combine them into a temporary table in my application. I get data using a pass-through query dynamically created in code: mySQL = "SELECT...
0
by: taras.di | last post by:
Hi everyone, I've come across an extremely strange problem. The exact same query in both mysql command line client, and mysql query browser gives entirely different results. I was hoping someone...
5
by: deaconj999 | last post by:
Hi, I have nearly finished my database and I would like to add a query that uses a combo box to get the results, not the usual paramater style input. I suppose it would need a form and a query...
1
by: tomlebold | last post by:
Having problems displaying query results from combo boxes on a sub form, which is on the same form that is used to select criteria. This has always worked form me when displaying query results on...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.