English 中文(简体)
利用“按顺序”加入MySql?
原标题:using "order by" on inner join MySql?
  • 时间:2011-06-02 17:15:34
  •  标签:
  • php
  • mysql

hello Master around the world, im here re with a problem :D

现在,一只大麻就给你带来一些简单的东西,但是实际上,在方案编制和q方面,我一刀切,因此需要更多的学习。

ok,让问题发生。 我对此有一些怀疑。

SELECT
eu_product.*,
eu_shop_display.display_name as dname,
eu_product_img.image_url as img
FROM eu_product
INNER JOIN eu_product_img on eu_product_img.product_id = eu_product.product_id
INNER JOIN eu_shop_display on eu_shop_display.display_id = eu_product.product_display
where eu_product.publish=1
and eu_product.shop_id=1
and eu_product.product_display IN (select display_id from eu_shop_display where parent_id=1) 
or eu_product.product_display = 1
GROUP BY eu_product.product_id 
ORDER BY eu_product.product_id DESC  LIMIT 0, 10

问题在于:

INNER JOIN eu_product_img on eu_product_img.product_id = eu_product.product_id

表格如上。

“entergraph

我需要利用ASC关于“列入名单”的指令。

是否可使用两种命令,或者能否通过内心加入来补充秩序? i 尝试增加

ORDER BY eu_product.product_id DESC, eu_product_img.listing ASC

但不工作:

maybe someone can explain how its work.


<>>>>>

& & ;

表格

“enterography

该产品

“entergraph

结果

“entergraph

但是,“产品-产品-产品-产品-产品-产品”没有正确操作:

i 需要在产品_id 1上列名,而不是4

see the table product_img

i 需操作产品。 在加入后,先列入ASC命令。

正确的问题就好了。

SELECT eu_product.product_id, 
(select img.listing from eu_product_img as img where img.product_id = eu_product.product_id order by img.listing ASC limit 1 ) as listing 
    FROM eu_product 
    where eu_product.shop_id=1 
    or eu_product.product_display = 2 
    GROUP BY eu_product.product_id 
    ORDER BY eu_product.product_id DESC  LIMIT 0, 20

因此,它不能利用内心加入?

此前的感谢。

Regard, Stecy

最佳回答

它正在发挥作用。 你从屏幕上看到,他们首先通过产品补贴订购,然后通过列入名单。 如果你只是想通过列入名单来命令,那么就请上<代码>。 页: 1 eu_product_img.listing ASC. 如果你想把产品列入名单,以声明推翻你的命令。

命令接受多项声明,但结果将按你具体指明命令声明的顺序排列。 因此,如果首先列出名单,则首先列出结果等。

问题回答

暂无回答




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签