如何在2个mysql表中选择最大值行?

时间:2014-02-14 11:04:24

标签: mysql sql

我有两张表如下:

表:访客

---------------------
|     Code    |Contr|
|-------------------|
|225919528553 | 1003|
|-------------------|
|130324727131 | 1004|
|-------------------|
|353952972425 | 1010|
|-------------------|
|997498622785 | 1014|
|-------------------|
|
|
|

表:产品

-----------------------------
|    Code     | Name| Color |
|----------------------------
|225919528553 | Pen | Balck |
|----------------------------
|130324727131 | Book| White |
|----------------------------
|353952972425 | Fan | Black |
|----------------------------
|997498622785 | DVD |  Red  |
|----------------------------
|
|
|

我希望显示以下"Contr"列的更多值:

|    Code     | Name| Color | Contr |
|------------------------------------
|997498622785 | DVD |  Red  | 1014  |
|------------------------------------
|353952972425 | Fan | Black | 1010  |
|------------------------------------
|130324727131 | Book| White | 1004  |
|------------------------------------
|225919528553 | Pen | Balck | 1003  |
|------------------------------------
|
|

https://stackoverflow.com/revisions/f6f23a85-d8b8-4900-b72a-8ccb7b8abf25/view-source

3 个答案:

答案 0 :(得分:1)

尝试

SELECT p.*, v.Contr
FROM Visitor AS v
JOIN Products AS p ON p.Code = v.Code

答案 1 :(得分:1)

我会在表中找到更多价值!?

答案 2 :(得分:0)

select v.Code,
p.Name,
p.Color,
p.Contr 
from 
Visitor as v,
Products p 
where 
v.code=p.code order by contr