dongshu9458 2012-08-07 01:30
浏览 185

按ID分组并显示mysql的所有结果

I have 2 tables

tabcats - Cat_Id, Cat_Name
tabnews - News_Id, News_Name, Cat_Id

So I'm trying to make a select on database and return all results but using

Group by Cat_Id

so my results was supposed to be

let's say I have 3 Categories and 5 News

Results

    Cat_Name 1

  • News_Name (1)
  • News_Name (2)

    Cat_Name 2

  • News_Name (3)
  • News_Name (4)

    Cat_Name 3

  • News_Name (5)

I read something about using LEFT OUTER JOIN but I don't get this clearly.

  • 写回答

2条回答 默认 最新

  • dongmi4035 2012-08-07 01:50
    关注

    First you need to be clear about yourself. What I supposed that you tried to do is select some counts of latest news,isn't it? Try query similar to this one: The below query Find the course ID, semester, year and title of each course offered by the Comp. Sci. department

        select section.course_id, semester, year, title from section, course where section.course_id = course.course_id  and dept_name = ‘Comp. Sci.' 
    

    Ordering can be done as follows:

    return(mysql_query("SELECT  * FROM tabNews GROUP BY news_id DESC LIMIT *counts*"));
    
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100