473,378 Members | 1,403 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,378 software developers and data experts.

SELECT Query problem

I have the following table:
id | supRef | pmRef | status |
=====================
1 | 1 | 1 | 3 |
2 | 1 | 2 | 2 |
3 | 1 | 3 | 2 |
4 | 1 | 4 | 3 |
5 | 2 | 1 | 2 |
6 | 3 | 1 | 2 |
7 | 3 | 2 | 3 |
I need to create two queries, the first is simple:
SELECT * FROM table WHERE pmRef=1 AND status = 2

this is to show all suppliers with status of 2 (new) for a given purchasing
manager
The second table is a little more tricky (for me anyway)

When a purchasing manager updates a supplier, the status is set to 4 for
approved or 3 for declined.
After all purchasing managers have approved / declined the suppiler status
is changed accordingly
I need to be able to display a set of suppliers who have yet to be approved
/declined (status = 2) by other purchasing managers - and show the supplier
only once. It also needs to NOT SHOW the suppliers that are not associated
with a purchasing manager

eg:
id | supRef | pmRef | status |
=====================
2 | 1 | 2 | 2 |
3 | 1 | 3 | 2 |
any help would be very grateful

Craig
Jul 23 '05 #1
1 1115

"Craig Keightley" <do**@spam.me> wrote in message
news:42*********************@news-text.dial.pipex.com...
I have the following table:
id | supRef | pmRef | status |
=====================
1 | 1 | 1 | 3 |
2 | 1 | 2 | 2 |
3 | 1 | 3 | 2 |
4 | 1 | 4 | 3 |
5 | 2 | 1 | 2 |
6 | 3 | 1 | 2 |
7 | 3 | 2 | 3 |
I need to create two queries, the first is simple:
SELECT * FROM table WHERE pmRef=1 AND status = 2

this is to show all suppliers with status of 2 (new) for a given
purchasing manager
The second table is a little more tricky (for me anyway)

When a purchasing manager updates a supplier, the status is set to 4 for
approved or 3 for declined.
After all purchasing managers have approved / declined the suppiler status
is changed accordingly
I need to be able to display a set of suppliers who have yet to be
approved /declined (status = 2) by other purchasing managers - and show
the supplier only once. It also needs to NOT SHOW the suppliers that are
not associated with a purchasing manager

eg:
id | supRef | pmRef | status |
=====================
2 | 1 | 2 | 2 |
3 | 1 | 3 | 2 |
any help would be very grateful

Craig


So far, i have managed to create the following select statements from above
eg using pmRef of 1

id | supRef | pmRef | status |
=====================
1 | 1 | 1 | 3 |
2 | 1 | 2 | 2 |
3 | 1 | 3 | 2 |
4 | 1 | 4 | 3 |
5 | 2 | 1 | 2 |
6 | 3 | 1 | 2 |
7 | 3 | 2 | 3 |
8 | 4 | 1 | 3 |
9 | 4 | 2 | 2 |

SELECT * FROM table WHERE pmRef = 1 AND status = 2

id | supRef | pmRef | status |
=====================
2 | 1 | 2 | 2 |
9 | 4 | 2 | 2 |

Now for each of the above rows, I create a SELECT statement (generated using
PHP):

SELECT * FROM table WHERE supRef = 1 AND pmRef <> 2 AND status <> 2
SELECT * FROM table WHERE supRef = 4 AND pmRef <> 2 AND status <> 2

Combined Result:

id | supRef | pmRef | status |
=====================
1 | 1 | 1 | 2 |
4 | 1 | 4 | 3 |
8 | 4 | 1 | 3 |

Is there a more efficient way of doing this?
Any help please
Craig
Jul 23 '05 #2

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

Similar topics

3
by: Ian T | last post by:
Hi, I've got what I think (probably incorrectly) should be a simple SELECT : Two colums with data like col1 col2 1 50 1 51 2 50
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
1
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
2
by: Pavel Stehule | last post by:
Hello, Pg make query 1. and 2. very fast (use index), but for query 3. dont use index. I can solve its using select union, but I readed so pg 7.5 don't problem with OR operator. I use cvs pg. I...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
2
by: VMB | last post by:
Using version: 4.0.18-Max-log We're getting some fairly poor performance when doing an INSERT INTO temp_table ... SELECT (...). The SELECT is grabbing 2K row chunks from its table, so the...
12
by: bokke | last post by:
Hi, I have a page with a link <a href="Contributor.php?action=&SubCat=<?php echo $row; ?>"><?php echo $row;?></a> that does to a page with a SELECT $query = "SELECT * FROM news WHERE...
4
by: Konrad Hammerer | last post by:
Hi! I have the following problem: I have a query (a) using another query (b) to get the amount of records of this other query (b), means: select count(MNR) as Number from...
1
by: zafm86 | last post by:
Hi everyone! I'm sure my problem is pretty easy to solve but I've been working on it for a long and my my brain is not working correctly anymore. I'm working with an AS400 and I mhave to do an...
4
by: The.Daryl.Lu | last post by:
Hi, Have a bit of a problem... I've created a form in Access and will use the form for a user to query a table based on the selected fields. The problem lies in that I was using checkboxes for...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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...

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.