473,406 Members | 2,849 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,406 software developers and data experts.

Challenge: complex sql instruction?

2
I'll explain my problem using a little example

table
article name price
-------------------------------
art1 Default 10
art2 Default 15
art2 Egmond 12
art3 Default 20
art3 Windels 17

Goal:
Article prices are saved with customer name Default. When one customer has a specific price, the customer's name is used (ex. customer Egmond can buy article art2 for 12 €; other customers have to pay 15 €).
If a customer has no specific price for an article, the default price must be shown.

Using one query, I should be able to get the catalog for customer Egmond:
art1 10 €
art2 12 €
art3 20 €

Can somebody help me?
Nov 23 '07 #1
1 989
amitpatel66
2,367 Expert 2GB
I'll explain my problem using a little example

table
article name price
-------------------------------
art1 Default 10
art2 Default 15
art2 Egmond 12
art3 Default 20
art3 Windels 17

Goal:
Article prices are saved with customer name Default. When one customer has a specific price, the customer's name is used (ex. customer Egmond can buy article art2 for 12 €; other customers have to pay 15 €).
If a customer has no specific price for an article, the default price must be shown.

Using one query, I should be able to get the catalog for customer Egmond:
art1 10 €
art2 12 €
art3 20 €

Can somebody help me?
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT * from table1 WHERE name = 'Default' AND article NOT IN(SELECT aricle from table1 WHERE name = 'Egmond')
  3. UNION
  4. SELECT * from table1 WHERE name = 'Egmond'
  5.  
  6.  
  7.  
Nov 25 '07 #2

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

Similar topics

1
by: Andr? Roberge | last post by:
In 1981, Richard Pattis wrote a delightful little book titled "Karel the Robot, a Gentle Introduction to the Art of Programming." Pattis's "Karel the Robot" was named after the author Karel Capek,...
1
by: Tim Clacy | last post by:
Be a hero and show me a good model of a hardware device register :-O This might seem like an absurd challenge; after all, the C++ language has been around for donkeys years now. It's a mature...
0
by: Stephen | last post by:
This is a real brain-teaser and i'd really appreciate it if someone can try and understand what im trying to do and give me a few pointers or ideas to help me work out my problem. Im basically...
8
by: Frank Buss | last post by:
A new challenge: http://www.frank-buss.de/marsrescue/index.html Have fun! Now you can win real prices. -- Frank Buß, fb@frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de
0
by: Richard Jones | last post by:
The date for the second PyWeek challenge has been set: Sunday 26th March to Sunday 2nd April (00:00UTC to 00:00UTC). The PyWeek challenge invites entrants to write a game in one week from...
0
by: richard | last post by:
The date for the second PyWeek challenge has been set: Sunday 26th March to Sunday 2nd April (00:00UTC to 00:00UTC). The PyWeek challenge invites entrants to write a game in one week from...
9
by: Greg Buchholz | last post by:
/* While writing a C++ version of the Mandelbrot benchmark over at the "The Great Computer Language Shootout"... http://shootout.alioth.debian.org/gp4/benchmark.php?test=mandelbrot&lang=all ...
78
by: wkehowski | last post by:
The python code below generates a cartesian product subject to any logical combination of wildcard exclusions. For example, suppose I want to generate a cartesian product S^n, n>=3, of that...
25
by: jacob navia | last post by:
The C99 standard forgot to define the printf equivalent for complex numbers Since I am revising the lcc-win implementation of complex numbers I decided to fill this hole with "Z" for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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
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
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...
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
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...

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.