473,416 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

SQL Statement Help

I need some help with a SQL statement (SQL Server 2k).

I have three tables, an Artists table which holds user info, a Types table
which holds the TypeID and Description for different types (I.e. visual,
musician, etc) and an Artists_Types table, which stores Type_ID information
for each Artist _ID. Each Artist can have more than one type.

Artists Table:
Artist_ID|First_Name|Last_Name....
1 |Joes |Blogs

Types Table:
Type_ID | Desc
1 | Visual Artist
2 | Digital Artist

Artists_Types Table:
Artist_ID(fk)|Type_ID(fk)
1 | 2
1 | 3
1 | 5
2 | 2
2 | 6
I have a checkbox list that allows the users to select these type IDs. I
now want to query Artists_Types table for an Artist_ID that has ALL of the
types they select. For example, if they select types 2, 3, and 5 it should
return Artist_ID 1 because it has all three. The Select statement will need
to join the Artist and Artists_Types tables.

Any help would be greatly appreciated.

Thanks,
Nathan
Nov 19 '05 #1
2 1058
WJ
create table myTable
(
Artist_ID int
,Type_Checked int
)

declare @all int
set @all=3

insert myTable
select
a.Artist_ID
,count(b.Type_ID)
from Artist a
,Artists_Types b
,Types c
where a.Artist_ID=b.Artist_ID
and b.Type_ID=c.Type_ID
group by Artist_ID

Select Artist_ID from myTable where Type_Checked=@all
go
----------
John

"NathanV" <Na*****@discussions.microsoft.com> wrote in message
news:A9**********************************@microsof t.com...
I need some help with a SQL statement (SQL Server 2k).

I have three tables, an Artists table which holds user info, a Types table
which holds the TypeID and Description for different types (I.e. visual,
musician, etc) and an Artists_Types table, which stores Type_ID
information
for each Artist _ID. Each Artist can have more than one type.

Artists Table:
Artist_ID|First_Name|Last_Name....
1 |Joes |Blogs

Types Table:
Type_ID | Desc
1 | Visual Artist
2 | Digital Artist

Artists_Types Table:
Artist_ID(fk)|Type_ID(fk)
1 | 2
1 | 3
1 | 5
2 | 2
2 | 6
I have a checkbox list that allows the users to select these type IDs. I
now want to query Artists_Types table for an Artist_ID that has ALL of the
types they select. For example, if they select types 2, 3, and 5 it
should
return Artist_ID 1 because it has all three. The Select statement will
need
to join the Artist and Artists_Types tables.

Any help would be greatly appreciated.

Thanks,
Nathan

Nov 19 '05 #2
WJ
> group by Artist_ID

GROUP BY A.ARTIST_ID instead

John Webb

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Robert Mark Bram | last post by:
Hi All! I have the following two methods in an asp/jscript page - my problem is that without the update statement there is no error, but with the update statement I get the following error: ...
4
by: James E Koehler | last post by:
I can't get the WHILE statement to work in MySQL. The version of MySQL that I am using is: Ver 12.16 Distrib 4.0.6-gamma, for Win95/Win98 (i32) running on Windows MX. Here is the relevant...
2
by: Little PussyCat | last post by:
Hello, I hope you can help me. We have a SQL Server 2000 database at work, (which works with a VB6 frontend) which grew to a considerable size, so one of my past colleagues sent me this...
5
by: WindAndWaves | last post by:
Hi Team The function below searches all the tables in a database. However, if subsearch = true then it searches all the objects listed in a recordset (which are all table names). I thought to...
11
by: Scott C. Reynolds | last post by:
In VB6 you could do a SELECT CASE that would evaluate each case for truth and execute those statements, such as: SELECT CASE True case x > y: dosomestuff() case x = 5: dosomestuff() case y >...
10
by: John Smith | last post by:
Can you do a Select Statement within a Select Statement? I want to build a query similar to queries built in Access which link to other queries but using only SQL Statements. Is it possible? If...
6
by: FayeC | last post by:
I really need help figuring this out. i have a db with mostly text fields but 2. The user_id field is an autonumber (key) and the user_newsletter is a number (1 and 0) field meaning 1 yes the ...
4
by: Jack | last post by:
Hi, I have a asp page where part of the code is as follows. This builds up the sql statement partially. sql01 = "UPDATE EquipmentTbl SET " sql01 = sql01 & "SerialNumber = '" &...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.