sql - cross referencing with queries -


i've been working sql 6 months now. i'm pretty adept when comes pulling information tables , sorting when want compare or cross reference multiple tables, little more shaky. mean should simple answer. i'm guessing i'm not thinking of correct clause , need select distinct 1 of tables.

i'm going try explain question thoroughly can without using specific names. general situation i'm trying check this. i've got toolbox has assortment of tools in it. have list of tasks might need , list of problems might performing tasks , using tools on. i've got table tools has columns descriptions of tools, unique id tools, , classification tools (power tools, manual tools, building materials, etc.). table different tasks. columns task descriptions, , unique id. primarily, want write query can show me tools might labeled power tools aren't being used specific task.

here's sample of code. has more tables because in reality data spread out among more tables 3, concept should remain same.

select tools.tooldescription,   tools.toolsid,   tools.classification,   tasks.taskdescription,   tasks.taskid,   problems.problemdescription,   problems.problemid [lots of inner joins aren't relevant without actual tables] tools.classification = 'power tools' 

if want power tools aren't assigned tasks, why have tasks fields in result set?

select tools.tooldescription,        tools.toolsid,        tools.classification   tools  tools.classification = 'power tools'; 

this query returns power tools. simple excellent starting point.

now want filter out power tools assigned tasks. that's easy in sql. outer join lets keep unmatched tools. don't show relevant tables let's tasks table contains toolsid field every tool used in task.

select  tools.tooldescription,         tools.toolsid,         tools.classification    tools left join tasks     on  tasks.toolid = tools.toolid   tools.classification = 'power tools'     , tasks.toolid null; 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -