English 中文(简体)
附有条件的声明
原标题:SQL Statement with a condition
  • 时间:2012-04-25 18:35:03
  •  标签:
  • php
  • mysql
  • sql

我有以下资历:

SlectT a.name_f, a.uid, a.name_l, a.profile_pic, b.position fromuser a groups_ members b, WHERE a.uid = b.userid and b.group_id=$group_var

这发挥了巨大作用,使小组中的所有用户以及他们在小组中的职位都回到了我想要呼吁的任何集团。 当小组参加活动时,我想在活动页上提及上述职能,但还要补充说明是否确认该用户。 因此,我提出以下问题:

SlectT a.name_f, a.uid, a.name_l, a.profile_pic, b.position, c.confirmed fromuser a groups_ members b, event_users c WHERE a.uid = b.userid and b.group_id=$group_var and c.event_var and a.uid = c.userid

这也发挥了巨大作用,但在我出现问题时也是如此。 让我们假设,某个群体已经创造了一个活动,随后,所有用户都被丢到活动桌上。 我的第2次问询仍将是该小组及其经确认的环境的每个用户,但当新用户加入小组并选择其立场时,新的用户不会在我的第二问询中回来,因此,显示所有用户及其立场的事件,不说明在事件发生后增加的任何新用户。

我希望,这种说法过于混淆。 我的表格如下:

event_users || id, event_id, userid, confirmed    

groups_members || id, userid, group_id, position

users || uid, name_f, name_l, profile

My question is how can I basically collect all of the current group members and subsequently if they have been entered into the event_users table, what is their confirmed status. I do not want to run queries on my group page that accounts for new users and puts them into any events that the group has

最佳回答

左边使用:

    SELECT 
      a.name_f, a.uid, a.name_l, a.profile_pic, b.position, c.confirmed 
    FROM users a 
    JOIN groups_members b on a.uid = b.userid
    LEFT JOIN event_users c on a.uid = c.userid
    WHERE b.group_id= $group_var  and c.event_id = $event_var 

如果在用户表中没有对应记录,你将获得UNL的确认价值。 2. 您可使用共同代谢功能,以设定违约值:

     coalesce(c.confirmed, 0)

     coalesce(c.confirmed,  not subscribed yet )
问题回答

暂无回答




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

热门标签