Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1

    Default mysql select two tables problem


    Hi guys, i know most of you naka agi na ani, im still new and basic pa ako nahibaw.an sa mysql then diri ko na ungot kay nag ka lisod na ako query

    how do you join two tables?

    this is my problem.

    -I have a 'user' table and 'notifications' table
    -in the 'user' table naa koy user_id, email
    -in the 'notifications' table naay user_id, status

    I want to get the email sa user table where ang notifications.status = 1

    need help

  2. #2
    btw, i found my own way but also want to know if naa pay mas nindot na solution

    SELECT DISTINCT users.email, notifications.user_id FROM users, notifications WHERE notifications.user_id = users.user_id AND notifications.status = 1

  3. #3
    try this:

    Code:
    SELECT u.email, n.user_id 
     FROM users u JOIN notifications n 
     ON u.user_id = n.user_id
     WHERE n.status = 1

  4. #4
    thanks sir, it worked the same as my query, pero is there any difference in using JOIN and just plainly FROM two tables

    btw, dili na diay needed ang DISTINCT sa ako query

  5. #5
    naay difference ang JOIN and select FROM 2 tables sir kung mogamit ka ug other types of JOIN. like LEFT JOIN, RIGHT JOIN ug OUTER JOIN. pero kanang JOIN/INNER JOIN pareho ra mn cguro.

    edit:
    pareha ra diay according to wiki. ang nkalahi ra ky ang tawag. explicit ug implicit join notation. heheh

  6. #6
    gamit ka distinct kong gusto ka unique ang result, gamit ka join kong naa relationship ang 2 or more tables.

  7. #7
    SELECT u.email, u.user_id
    FROM users u
    WHERE EXISTS(
    SELECT n.user_id
    FROM notifications n
    WHERE n.user_id = u.user_id AND n.status = 1)

  8. #8
    hi guys, i've came across another problem. How do i select all fields from one table and only 1 or 2 fields from another table?

  9. #9
    select t1.*,t2.col1,t2.col2 from table1 t1,table2 t2
    //condition sample
    where t1.id=t2.id and t2.id=something

  10. #10
    Quote Originally Posted by krissy86 View Post
    hi guys, i've came across another problem. How do i select all fields from one table and only 1 or 2 fields from another table?
    -I have a 'user' table and 'notifications' table
    -in the 'user' table naa koy user_id, email
    -in the 'notifications' table naay user_id, status

    SELECT a.*, b.user_id, b.status FROM user a, notifications b WHERE a.user_id=b.user_id AND b.status=1

  11.    Advertisement

Page 1 of 2 12 LastLast

Similar Threads

 
  1. Replies: 12
    Last Post: 05-07-2009, 02:36 PM
  2. Two problems...
    By sagoy in forum Computer Hardware
    Replies: 20
    Last Post: 07-24-2008, 11:18 PM
  3. The Problem of Selectivity
    By mordecai_327 in forum Spirituality & Occult - OLDER
    Replies: 5
    Last Post: 11-21-2007, 04:51 PM
  4. Replies: 7
    Last Post: 04-17-2006, 12:35 PM
  5. problem : Nesting CSS Tables
    By $dbpasswd in forum Websites & Multimedia
    Replies: 2
    Last Post: 07-12-2005, 10:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top