Log in

View Full Version : Need help with a query ...



pepe_lepew1962
04-30-2010, 06:35 PM
Hello:

I am trying to get a mysql query together an not quite sure how to apply it, whether it is with distinct, join and all. What I am looking is to get the ID, qty ( number of users ), max and min number. Can anyone help me with this please.


Name ID Name
123ABC Engine
649DFA Transmission
854UDF Window


User ID User Name User Amount
123ABC Paul 300
123ABC John 190
649DFA Ian 500
123ABC Mary 210
123ABC Mark 225
649DFA Steve 360




Required Result:

ID Qty Max Mix
123ABC 4 300 190
649DFA 2 500 360

bluewalrus
04-30-2010, 07:19 PM
So you have 2 tables one with 3 columns and one with 4 linked with ID?

pepe_lepew1962
04-30-2010, 07:33 PM
Yes Blue.
I dont know why they bunched thme together. Thew link would be in the ID.

Name ID, Name


User ID, User Name, User Amount

james438
05-01-2010, 01:32 AM
most browsers will condense whitespace. I don't know why. I find it rather annoying myself. To get around it you will need to use non-breaking spaces. In this forum I believe the only way to do that is to use   to create the HTML version of it.

Other than that I recommend wrapping your code with code tags for readability.

I see that you have two tables. One table has three columns, but only two of which have data. In your second table you have three columns and data for all three columns, but I usually read spaces between table names as separators.

test           test

djr33
05-01-2010, 01:55 AM
For this sort of thing a <table> might be the best way to do it. Tables aren't always a good idea, but for tabular data they're great.

The reason that HTML ignores whitespace is because that is normal for all programming languages. Formatting is ignored and only the commands and text content are included. It is annoying for HTML, though it also helps because you can use tabs to organize the code, etc.

bluewalrus
05-01-2010, 02:13 AM
I think the OP is looking for a sql statment not html help, also the entity for a space can also be &nbsp;.



GO
SELECT a.name, a.ID, a.name, b.User, b.ID, b.name, b.amount
FROM table1 AS a
INNER JOIN table2 AS b
ON a.id = b.id

Not familiar with max and min functions

http://www.techonthenet.com/sql/min.php
http://www.techonthenet.com/sql/max.php

james438
05-01-2010, 03:36 AM
also the entity for a space can also be &nbsp;.
not quite as seen in the following example:

test&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;test

I do believe you understand the question best. I was/am having trouble reading the question in the first post.