0

I have 4 tables with columns as illustrated below Table1: PART with the following columns | PID | PCODE| PNAME| MID|

Table2: MAN with the following columns | MID | MCODE| MNAME |MVALID|

Table3: LVL with the following columns. |PID | QUANTITY|

Table4: AVAIL with the following columns |MID | MAVAILABLE|

I want the query output in this form <PCODE>,<MCODE>,<QUANTITY>,<MNAME> so I tried the following sql:

select 
    part.pcode,
    man.mcode,
    lvl.quantity,
    man.mname
    from man
    inner join avail on man.mid = avail.mid
    inner join part on man.mid = avail.mid
    inner join lvl on part.pid = lvl.pid 
    where PNAME like '%phyll%'
        and MAVAILABLE = 'YES'


However when I execute it takes forever that I end up terminating, Also the max rows of the tables is 500. Is there anywhere I am making an error?

Edit: New question: using a WHERE clause (with this statement only, where PNAME like '%phyll%' reduces execution time and works, however adding the and MAVAILABLE = 'YES' to filter MAVAILABLE rows that contain the word YES produces 0 results but there are a number of results with YES in the columns. Is there any error here? the MAVAILABLE column containts either YES or NO strings only

Abel
  • 113
  • 4

1 Answers1

1

Try

select 
   part.pcode,
   man.mcode,
   lvl.quantity,
   man.mname
from man
inner join avail on man.mid = avail.mid
inner join part  on man.mid = part.mid     -- I made a change here
inner join lvl   on part.pid = lvl.pid 
where PNAME like '%phyll%'
    and MAVAILABLE = 'YES'
Paul Vernon
  • 3,818
  • 1
  • 10
  • 23
  • This produces 0 results – Abel Sep 22 '22 at 11:11
  • Often the best way to "debug" a SQL query is to cut-it down into a simpler one, then build it up until it "goes wrong". So, for example you could start with `SELECT COUNT(*) FROM avail WHERE MAVAILABLE = 'YES'` then, if that is OK, try `SELECT COUNT(*) FROM man inner join avail on man.mid = avail.mid WHERE MAVAILABLE = 'YES'` etc until you can work out *yourself* where *your* problem lies... – Paul Vernon Sep 22 '22 at 14:13