Skip to content
Advertisement

SQL query to filter columns

I have a question regarding the SQL query. I have this table shown below

Region Rep Item
Quebec Jones Pencil
Ontario Kivell Binder
Ontario Jardine Pencil
Ontario Gill Pen
Alberta Sorvino Pencil
Quebec Jones Binder
Ontario Andrews Pencil
Ontario Jardine Pencil
Alberta Thompson Pencil
Quebec Jones Binder
Ontario Morgan Pencil
Quebec Howard Binder
Alberta Sorvino Pen
Alberta Thompson Binder
Ontario Andrews Pencil
Ontario Jardine Binder
Ontario Jardine Binder
Ontario Andrews Binder

I have to filter for each Region then for each Rep and lastly for each Item. So like one example of a table should look like this:

Region Rep Item
Quebec Jones Pencil

And then I have to go back and choose(filter) the other item and the table should look like this:

Region Rep Item
Quebec Jones Binder
Quebec Jones Binder

After I copied these two tables I have to go back to Rep and chose the other value and again filter item column again the same to get the tables. After I am done with all Rep and Item I have to go back and choose another Region and repeat the same steps

How can I achieve this with a query?

Advertisement

Answer

If I correctly understood your task, you need few different queries (please, replace table_name with yours):

SELECT * 
FROM `table_name` 
WHERE `Region` LIKE 'Quebec' 
    AND `Rep ` LIKE 'Jones' 
    AND `Item` LIKE 'Pencil'
SELECT * 
FROM `table_name` 
WHERE `Region` LIKE 'Quebec' 
    AND `Rep ` LIKE 'Jones' 
    AND `Item` LIKE 'Binder'
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement