Inner Joins

Inner Joins

devinder1995devinder1995 Posts: 5Questions: 2Answers: 0

I am not getting what is the syntax to write inner join ,only left join syntax is mentioned in manual?Need help

select t.name,
c.name,s.company_name,t.start_date,t.end_date,t.start_budget,t.end_budget,t.start_actual,t.end_actual,t.cost_code,t.gst from task t,project p,suppliers s,category c where t.supplier_id=s.id and p.id=t.project_id and c.id=t.category_id

This is the query i am trying to write a join for i am using latest trial version of editor

This question has accepted answers - jump to:

Answers

  • rf1234rf1234 Posts: 2,982Questions: 87Answers: 421
    edited May 2018 Answer ✓

    Editor doesn't provide an INNER JOIN but you can use LEFT JOIN and check for IS NOT NULL regarding the key you are joining. That gives you the same result.

    select 
    t.name,
    c.name,
    s.company_name,
    t.start_date,
    t.end_date,
    t.start_budget,
    t.end_budget,
    t.start_actual,
    t.end_actual,
    t.cost_code,
    t.gst
    from task t, project p, suppliers s, category c 
    where t.supplier_id = s.id 
        and p.id = t.project_id 
        and c.id = t.category_id
    

    can be written as

    SELECT
    t.name,
    c.name,
    s.company_name,
    t.start_date,
    t.end_date,
    t.start_budget,
    t.end_budget,
    t.start_actual,
    t.end_actual,
    t.cost_code,
    t.gst
    FROM task t
    LEFT JOIN category c   ON  c.id = t.category_id
    LEFT JOIN project p    ON  p.id = t.project_id 
    LEFT JOIN suppliers s  ON  s.id = t.supplier_id
    WHERE c.id IS NOT NULL
      AND p.id IS NOT NULL
      AND s.id IS NOT NULL
    

    Just write this the Editor way with the back end library you are using (PHP or whatever you are using).

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer ✓

    Awesome - thanks @rf1234. I've bookmarked this myself.

    Allan

  • devinder1995devinder1995 Posts: 5Questions: 2Answers: 0

    Thanks a lot .It is working now

This discussion has been closed.