Jay Fisher

Use AND, OR and comparison operators in WHERE

Use of AND, OR, comparisons in WHERE .Decided to include INNER JOINS so that information was more readable rather than just numbers.

  • October 26, 2017 at 8:28 PM
  • Visible to public
/*Query 1 - List those signs that would be considered "Banners" based on dimensions and material*/
SELECT CONCAT(Signs.hor_dimens, ' ft x ', Signs.vert_dimens, ' ft') as 'Banners', Materials.name as 'Material', Finishes.name as 'Finish', Signs.quantity as 'Quantity', Signs.cost as 'Cost'
FROM Signs 
INNER JOIN Materials ON Signs.mat_id=Materials.mat_id
INNER JOIN Finishes ON Signs.finish_id=Finishes.finish_id
WHERE (Signs.hor_dimens>4 or Signs.vert_dimens>4) and Signs.mat_id != 5 and Signs.mat_id != 6;
/*Query 2 - List those signs that would be considered "Posters" based on dimensions and material*/
SELECT CONCAT(Signs.hor_dimens, ' ft x ', Signs.vert_dimens, ' ft') as 'Posters', Materials.name as 'Material', Finishes.name as 'Finish', Signs.quantity as 'Quantity', Signs.cost as 'Cost'
FROM Signs 
INNER JOIN Materials ON Signs.mat_id=Materials.mat_id
INNER JOIN Finishes ON Signs.finish_id=Finishes.finish_id
WHERE (Signs.hor_dimens<4 and Signs.vert_dimens<4) and Signs.mat_id != 5 and Signs.mat_id != 6;
/*Query 3 - List those signs that are printed on adhesive material*/
SELECT CONCAT(Signs.hor_dimens, ' ft x ', Signs.vert_dimens, ' ft') as 'Adhesive Signs', Materials.name as 'Material', Finishes.name as 'Finish', Signs.quantity as 'Quantity', Signs.cost as 'Cost'
FROM Signs 
INNER JOIN Materials ON Signs.mat_id=Materials.mat_id
INNER JOIN Finishes ON Signs.finish_id=Finishes.finish_id
WHERE Signs.mat_id = 5 or Signs.mat_id = 6;
/*Query 4 - List those signs that can be used outside by excluding those with certain materials*/
SELECT CONCAT(Signs.hor_dimens, ' ft x ', Signs.vert_dimens, ' ft') as 'Outdoor Ready', Materials.name as 'Material', Finishes.name as 'Finish', Signs.quantity as 'Quantity', Signs.cost as 'Cost'
FROM Signs 
INNER JOIN Materials ON Signs.mat_id=Materials.mat_id
INNER JOIN Finishes ON Signs.finish_id=Finishes.finish_id
WHERE Signs.mat_id != 4 and Signs.mat_id != 6;