Solved

SQL Query

Posted on 2006-06-14
2
251 Views
Last Modified: 2010-04-23
Hey,

in sql server I have two tables. First table is Items. It has two fields, ItemName and ItemCategory. I have a second table, called Categories. It has two fields, Category and AddToList. I want to write ONE query that selectes all Items where the AddToList boolean of the ItemCategory is set to 1. How can I do this? Redesigning the tables is not an option.

e.g.:
Item
====
ItemName: Ventureli
ItemCategory: BIKE
ItemName: Porsche
ItemCategory: CAR
ItemName: BMW
ItemCategory: CAR

ItemCategory
============
Category: BIKE
AddToList: 0
Category: CAR
AddToList: 1

Output of query should be Porsche and BMW.
0
Comment
Question by:tsay
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 500 total points
ID: 16901690
Hi tsay,

Select * From Items I Inner Join ItemCategory IC On I.ItemCategory = IC.Category Where IC.AddToList = 1

Should do it.

Tim Cottee
0
 
LVL 5

Author Comment

by:tsay
ID: 16901958
Perfect, tnx
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

808 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