English 中文(简体)
SQL que
原标题:SQL foreach equivalent for query

Im having difficulties creating a query. I have googled a lot but did not find a fitting solution. I have a table called blog (parent) and a table called entry (child):

<><> /strong>

  • id
  • subject
  • owner

  • id
  • blog_id
  • published (1 = published, 0 = unpublished)
  • date_created (timestamp, when created and when published)

博客有多个条目。 其他用户只看到已公布的条目。

我想提出一个问题,它预示着最近10个经过修改的博客。 为此,可能需要在LQ中设置一个相应的平台,以搜寻所有博客,并由最新的PUBLISHED条目(入境日期:经修改)下令使用,但只有F进入。 公开发表

My SQL knowledge is not on a level which allows me to create such a query. Additional info: using PHP (codeigniter) with MySQL

我试图这样做,知道这样做永远不会奏效,但可以帮助你作为我试图完成的工作的参考。

SELECT blog.id
FROM blog
JOIN entry ON entry.blog_id = blog.id
WHERE entry.published = 1
ORDER by entry.date_created desc
LIMIT 0, 10 

i want my end result to be the 10 blog.id s of which their child entry was published most recenlty. Can someone please help? All help is greatly appreciated.

如果在1个询问中无法做到这一点,也许有PHP,i可以做每个陈述,回答个人询问?

最佳回答

我认为这项工作将:

SELECT blog_id
FROM entry
WHERE published = 1
GROUP BY blog_id
ORDER BY MAX(date_created) DESC
LIMIT 0, 10
问题回答

这很可能是你们所需要的。

SELECT blog_id
FROM entry
WHERE published = 1
Group By blog_id
ORDER by date_created desc
LIMIT 0, 10




相关问题
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 ...

热门标签