Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

sql select query

Posted on 2008-06-19
7
Medium Priority
?
239 Views
Last Modified: 2010-04-21
I putting together a cosmetics ecommerce site. In the database every product has a BrandID and a CatID. I then have a page for Eyeshadows which will be CatID 6, Blushers CatID 2 etc.
I also have a category called brushes and an individual brushes page. However I also want the Eyeshadow brush to appear on the eyeshadow page but am not sure what the syntax would be for the query. My current query is:

SELECT * FROM items, itembrand, itemcategory, itemstocktypes WHERE items.ItemCatID = 6 AND items.ItemCatID=itemcategory.CatID AND items.ItemBrandID=itembrand.BrandID AND items.ItemStockID=itemstocktypes.StockID ORDER BY ItemID ASC

what can I add in to tell the database to also pull up items where ItemName contains the word 'brush' AND BrandID = 1
0
Comment
Question by:DallySP
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 750 total points
ID: 21821492
Do you want all needs to 1 .fullfill means ItemCatID = 6 , ItemName contanis brush , BrandID = 1

Or 2 .  Any one of them


For 1.

SELECT * FROM items, itembrand, itemcategory, itemstocktypes WHERE items.ItemCatID=itemcategory.CatID AND items.ItemBrandID=itembrand.BrandID AND items.ItemStockID=itemstocktypes.StockID  and
 items.ItemCatID = 6 AND Itemname Like'%brush%' AND itembrand.BrandID = 1
ORDER BY ItemID ASC

2 .

SELECT * FROM items, itembrand, itemcategory, itemstocktypes WHERE items.ItemCatID=itemcategory.CatID AND items.ItemBrandID=itembrand.BrandID AND items.ItemStockID=itemstocktypes.StockID and
( items.ItemCatID = 6 or Itemname Like'%brush%' or itembrand.BrandID = 1)
ORDER BY ItemID ASC
0
 
LVL 33

Expert Comment

by:jppinto
ID: 21821506
SELECT * FROM items, itembrand, itemcategory, itemstocktypes WHERE items.ItemCatID = 6 AND items.ItemCatID=itemcategory.CatID AND items.ItemBrandID=itembrand.BrandID AND items.ItemStockID=itemstocktypes.StockID AND ItemName  Like "*brush*" AND BrandID =1 ORDER BY ItemID ASC

jppinto
0
 

Expert Comment

by:suresh-infotech
ID: 21821519
hi.

add the following conditions in where clause.
Items.ItemName like 'brush%' AND Items.ItemBrandID = 1
0
Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

 
LVL 33

Expert Comment

by:jppinto
ID: 21821546
SELECT * FROM items, itembrand, itemcategory, itemstocktypes WHERE items.ItemCatID = 6 AND items.ItemCatID=itemcategory.CatID AND items.ItemBrandID=itembrand.BrandID AND items.ItemStockID=itemstocktypes.StockID AND Items.ItemName  Like "*brush*" AND Items.BrandID =1 ORDER BY ItemID ASC

jppinto
0
 

Expert Comment

by:jlib99
ID: 21821701
Untested but maybe cleaner:
select * from items
join itembrand on items.ItemBrandID=itembrand.BrandID
join itemcategory on items.ItemCatID=itemcategory.CatID
join itemstocktypes on items.ItemStockID=itemstocktypes.StockID
where items.ItemCatID = 6 or ( ItemName like  '%brush%') AND BrandID = 1)
order by ItemID ASC
0
 

Author Comment

by:DallySP
ID: 21822241
I'm going round in circles a bit here as I realise I've got my question slightly wrong as I only want to select the brushes that relate to the specific category. I've been trying out your various suggestions and adapting but have had not joy so far - probably my adaptions are incorrect. Just to clarify therefore I want to (and excuse my syntax as I know its wrong because it doesn't work!!:

SELECT * from items  WHERE items.CatID = 6 (AND items.CatID = 16 WHERE items.ItemSKU=6)
ie select all the eyeshadows and select all the brushes that relate to the eyeshadows

Hope that makes sense. CatID 6 is eyeshadows and CatID 16 is brushes and I've put a 6 in the ItemSKU field where the brush relates to eyeshadows but it doesn't work - I think I've got my brackets in the wrong place !!!
0
 

Author Closing Comment

by:DallySP
ID: 31468734
Hi - I used something based on your second solution in the end to solve this one - thanks for your help and apologies for the delay in getting back
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question