473,503 Members | 939 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

looking for a query

1 New Member
Hi,

here is my problem looking for this query that could help me.

I have a table paquet_product that has the following fields:
paquet - product
10 - 1
10 - 3
10 - 5
20 - 1
20 - 3
30 - 1

I would like to make a query which return me the paquet that have only the product 1 and 3.

whit this query:
select paquet from paquet_product where product IN(1,3) group by paquete having count(*) = 2;

i get return the 10 and the 20 but i just want the 20 because the 10 has also the 5.

anyone?

thanks
Apr 10 '07 #1
2 1107
iburyak
1,017 Recognized Expert Top Contributor
Try this:

Expand|Select|Wrap|Line Numbers
  1. declare @aaa table ( paquet int, product int)
  2.  
  3. insert into @aaa values(10, 1)
  4.  
  5. insert into @aaa values(10, 3)
  6. insert into @aaa values(10, 5)
  7. insert into @aaa values(20, 1)
  8. insert into @aaa values(20, 3)
  9. insert into @aaa values(30, 1)
  10.  
  11. select paquet
  12. from @aaa a
  13. Where product in (1,3)
  14. and not exists (select * from @aaa where paquet = a.paquet and product not in (1,3))
  15. Group by paquet
  16. having count(*) = 2
Good Luck.
Apr 10 '07 #2
mcasaurabhsumit
15 New Member
Write in this way and check the result:
Select paquet,product from paquet_product where product between 1 and 3 order by paquet


Hi,

here is my problem looking for this query that could help me.

I have a table paquet_product that has the following fields:
paquet - product
10 - 1
10 - 3
10 - 5
20 - 1
20 - 3
30 - 1

I would like to make a query which return me the paquet that have only the product 1 and 3.

whit this query:
select paquet from paquet_product where product IN(1,3) group by paquete having count(*) = 2;

i get return the 10 and the 20 but i just want the 20 because the 10 has also the 5.

anyone?

thanks
Apr 18 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2112
by: dawnunder | last post by:
eg. Someone fills out 3 fields. (There will be more but this is just to give you an idea) 1. Country? 2. State? 3. City I want this script to generate a web page and list the people by
3
2429
by: Thomas R. Hummel | last post by:
Hi, I was just helping a coworker optimize a query. He had two versions: one which used UNION for each value for which he was tallying results and another query which used GROUP BY. Here is an...
4
3262
by: Heejeong Lee | last post by:
I am going to begin following project Description of the project: One of the proposed ways of storing XML is to "shred" the structure of the XML document and insert it into a relational...
2
2334
by: Alex | last post by:
Subject: Looking for an XML (database-based) Query Reporting Tool/advice First off, let me apologize if this thread is somewhat off topic... PLEASE REPLY TO: xml@solex-bi.com I am looking...
4
2133
by: Diamondback | last post by:
I have two tables, WIDGETS and VERSIONS. The WIDGETS table has descriptive information about the widgets while the VERSIONS table contains IDs relating to different iterations of those widgets...
13
1732
by: Maxi | last post by:
I have a table (Table name : Lotto) with 23 fields (D_No, DrawDate, P1, P2,.....P21) and it has draw results from 1st Sep 2004 till date. I have another table (Table name : Check) with 15 fields...
3
1774
by: Rodney Garland | last post by:
Hi All, I am a relative beginner to Python and am looking for help with sending and XML message and getting back a return file. The server is: https://node.deq.state.or.us/node/node.asmx I...
1
1787
by: MD | last post by:
Hello I work in a .NET environment and I am about to create a development strategy. As part of this I am looking at implementing a testing tool to fit in with an iterative approach and NUnit...
7
1499
by: DanCole42 | last post by:
I've figured out a convoluted solution to this problem, but I'm hoping for something a bit more elegant. I have a table of orders as they're received from customers (the BillCust and Orders...
0
7089
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
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7339
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5581
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,...
1
5017
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
738
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
389
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.