Fetch same columns from two tables



  • I am very going through a very basic query and need help from Experts. Please help me. I am using "MySQL" here:

    SELECT c.first_name,
           c.last_name,
           c.email
           l.first_name,
           l.last_name,
           l.email
    from users u
    INNER JOIN contacts c ON u.id = c.user_id
    LEFT JOIN leads l ON c.id = l.contact_id
    where u.user_id=850
    -- and l.contact_id is not NULL
    

    Can I get the first_name, last_name in one column if contact id is not null in lead table.both table has same values

    I know I have not provided the good details but can provide if asked... any help will be appreciated.



  • A bit of guessing:

    SELECT c.first_name,
       c.last_name,
       c.email
       NULLIF(L.FIRST_NAME, C.FIRST_NAME) 
       ... 
       ... 
    from users u
    INNER JOIN contacts c ON u.id = c.user_id
    LEFT JOIN leads l ON c.id = l.contact_id
    where u.user_id=850
    

Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2