?
Solved

A MySQL language question?

Posted on 1999-12-22
10
Medium Priority
?
205 Views
Last Modified: 2006-11-17
I have this command:

  select MAX(Price) from Sales where Time=19991010

When running done.It can be return  19991010 day's Max Price,But how to return The ID field corresponding Max Price in one command£¿

And another I Select from two table,there is two way:

  A:use join
  B:where Table_One.ID=Table_Two.ID

How I choose it?

Thanks for you view!
0
Comment
Question by:bobe_aa
  • 4
  • 3
  • 2
  • +1
10 Comments
 

Author Comment

by:bobe_aa
ID: 2302314
Edited text of question.
0
 

Author Comment

by:bobe_aa
ID: 2302317
Edited text of question.
0
 

Author Comment

by:bobe_aa
ID: 2302318
Edited text of question.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 5

Expert Comment

by:aarie
ID: 2302694
Let's start with the first question...
If I'm not mistaken, you can get the corresponding ID by simply adding id to the query. The query would then look like:

select max(price),id from Sales where Time=19991010

The second question...
B is a way to join the two tables (that's what the part where table1.id = table2.id is for). Therefore, you don't need to choose. Your query would look like:

select FieldsFromTable1,FieldsFromTable2 from table1,table2 where table1.id = table2.id

This would select the specified fields from tables 1 and 2 where the id is the same.

Arjan.
0
 
LVL 2

Expert Comment

by:freshmeat
ID: 2304612
yes, i agree with aarie
0
 
LVL 5

Expert Comment

by:aarie
ID: 2309247
Bob, if my previously posted comment has helped you out, accept it as an answer. If not, let us know so we might be able to help you.

Arjan.
0
 

Accepted Solution

by:
ilia239 earned 200 total points
ID: 2311941
first question:

use this query:
select Price from Sales
Order by Price Desc Limit 1;

second question:
already clean?

0
 

Expert Comment

by:ilia239
ID: 2311950
i was wrong -
not "select Price from ..."
but "Select Price, Id from ...."
of course

but i think you understand it yourself!
0
 
LVL 5

Expert Comment

by:aarie
ID: 2312197
Bob, I suggest you REJECT ilia's answer, as it is almost a complete rip off of my comment.

Arjan.
0
 

Author Comment

by:bobe_aa
ID: 2321673
aarie,ilia239
Thanks for you help!
And thanks everyone.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question