douben6670 2013-05-16 19:00
浏览 76

SQL查询和PHP排序

I have two SQL tables:

users from which I need all email addresess which looks like:

---------------------
| id | email | pass | 

and user_answers from which I need all unique question ids which looks like:

-------------------------------------------------
| id | question_id | user_id | date_registrated |

Each user can answer few times on one question, for short I need:

array => $users_array[0] = array($user[email], $user[uniqe_ids], $user[date_registrated])
$users_array[1] = ...

How can I do it? I tried:

SELECT * FROM `".USERS_TABLE."` AS u LEFT JOIN `".QUESTION_TABLE."` AS c ON u.id = c.user_id
WHERE user_admin =".$user_id." ORDER BY u.email

and tried to sort it, bu with no effect.

  • 写回答

1条回答 默认 最新

  • doulu8446 2013-05-16 19:10
    关注

    Try this:

    select u.id,u.email,u.user_answers, c.question_id, c.date_registered
    from USERS_TABLE AS u LEFT JOIN QUESTION_TABLE AS c 
    ON u.id = c.user_id
    where u.id = ".$user_id." 
    ORDER BY u.email asc
    

    But this doesn't give anything meaningful to your scenario. kindly explain the scenario clearly.

    评论

报告相同问题?

悬赏问题

  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题