473,786 Members | 2,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1131

"Craig Keightley" <do**@spam.me > wrote in message
news:42******** *************@n ews-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
3548
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
6472
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 COULD be wrong... :) I've tried the access group...twice...and all I get is "Access doesn't like ".", which I know, or that my query names are too long, as there's a limit to the length of the SQL statement(s). But this works when I don't try to...
1
4178
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 couple of tables in my database using INNER JOINS and the WHERE clause to specify the required constraints. However, I also want to read two fields from a *single* record from a table called 'Locations' and then apply one of these field's values...
2
1910
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 used vacuum analyze first. table sp_op_product has 15K rows, sp_op_uct 37K rows; regards Pavel Stehule
6
4849
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 SalesManName AT Alan Time
2
6472
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 problem is not that the query results are so monstrous that it's just taking that long to gather them all. The problem appears to be one of IO. When an INSERT...SELECT is run, the SELECT part of the query is run first and those results saved in a...
12
1676
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 writer='$SubCat' ";
4
4299
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 Jahrbuch_Einzelversand_Komplett (while Jahrbuch_Einzelversand_Komplett is a query itself)
1
3618
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 "interface" in Access. It's like a little system to make a production plan. It must get information about part numbers, description, set where the part number belongs, quantity of part numbers that the set uses, stock number(this is a text value, it...
4
10585
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 the fields and noticed that if I don't check a box, then the query will look specifically in the table for where the applicable field is FALSE. This isn't right however and decided that I should use a radio button group so that the user can select...
0
9497
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7515
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.