www.webdeveloper.com
Results 1 to 4 of 4

Thread: Multiple querys in one

  1. #1
    Join Date
    Mar 2009
    Posts
    36

    Multiple querys in one

    Hi Folks,

    How can i edit the following query so that it is as it is currently, BUT also selecting only those where a record exists in t_dj (t_dj user_id and t_user user_id is the same)

    $result = mysql_query("SELECT * FROM t_user WHERE group_radio='1' ORDER BY second_name ASC");

    Thanks

  2. #2
    Join Date
    Jan 2008
    Location
    Florida
    Posts
    1,227
    Try:

    Code:
    SELECT U.* FROM t_user U,  t_dj DJ  WHERE U.group_radio='1' AND DJ.user_id = U.user_id ORDER BY U.second_name ASC

  3. #3
    Join Date
    Mar 2009
    Posts
    36
    Hi!

    Thanks very much for that. Thats almost perfect!
    Ive got the below query:-

    mysql_query("SELECT t_user.* FROM t_user,t_dj WHERE t_user.group_radio AND t_dj.user_id = t_user.id ORDER BY rand() LIMIT 8");

    BUT in the t_dj table there are sometime multiple records for the same user.
    I.E
    USER ID 0001, SHOW ID 0005
    USER ID 0002, SHOW ID 0005
    USER ID 0001, SHOW ID 0006
    (Basically if a user is on more than one show [radio])

    How can i change it so that it does pretty much the same, but i only want it to select each USER ID once.. Would i have to run this through another query?

  4. #4
    Join Date
    Jan 2009
    Posts
    3,346
    Use a GROUP BY clause.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles