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

How to query for conflicting values in a table?

dbrewerton
115 100+
I have this table in SQL that I'm trying to do some comparison work with. Thanks in advance for any help you can give me. Ok, onto the schema.

It's like this:

Expand|Select|Wrap|Line Numbers
  1. id (numeric, primary, not null, identity)
  2. number (varchar, Null)
  3. starttime (datetime, Null)
  4. endtime (datetime, Null)
  5. description (varchar, Null)
  6. subcategory (varchar, Null)
  7. category (varchar, Null)
  8. priority (varchar, Null) - Field is either Priority or Non-priority
  9.  
Now, what I want to do is query my database in this manner:

Display any records that conflict with only Non-priority conflict based on: priority based on the time of day and subcategory

Example: 234567 would conflict with 123456:

Expand|Select|Wrap|Line Numbers
  1. Display any records that conflict only Non-priority conflict based on: priority based on the time of day
  2.  
  3. Example: 234567 would conflict with 123456: 
  4.  
  5. Number              Starttime                Endtime            Priority              Category              Subcategory 
  6. 123456              00:00:00                05:00:00          YES                   ABC                     15 
  7. 234567              02:00:00                04:00:00          NO                    ABC                     ABC 
  8. 245368              06:00:00                08:00:00          NO                    ABC                     12                   
  9.  
  10. I'd like to output it like this: 
  11.  
  12. Number              Starttime                Endtime            Priority              Category              Subcategory            Conflicts_with 
  13. 234567              02:00:00                04:00:00          NO                    ABC                     ABC                     123456
Mar 9 '11 #1

✓ answered by Rabbit

Something like this should work
Expand|Select|Wrap|Line Numbers
  1. SELECT T2.*
  2. FROM Table1 AS T1, Table2 AS T2
  3. WHERE T1.Priority = "YES"
  4.    AND T2.Priority = "NO"
  5.    AND T2.Starttime <= T1.Endtime
  6.    AND T2.Endtime >= T1.Starttime

2 2102
Rabbit
12,516 Expert Mod 8TB
Something like this should work
Expand|Select|Wrap|Line Numbers
  1. SELECT T2.*
  2. FROM Table1 AS T1, Table2 AS T2
  3. WHERE T1.Priority = "YES"
  4.    AND T2.Priority = "NO"
  5.    AND T2.Starttime <= T1.Endtime
  6.    AND T2.Endtime >= T1.Starttime
Mar 9 '11 #2
dbrewerton
115 100+
That worked like a charm!!! Thank you so much!
Mar 9 '11 #3

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

Similar topics

2
by: Felix | last post by:
Hi, I've a problem: I want to have the result of my Mysql Query in a Table in my php file. Now I've this: <?
2
by: sreddy | last post by:
I am trying to write a sql query on self referencing table. Just to brief ..Database is related to a Hiring department of the Qwest company. I need to generate a Report used by in HR...
1
by: news | last post by:
Hello I have a problem with show all values from my database into my html page! Example of my database: Namn: test.mdb Table: tblTest Columns: col1, col2, col3 The thing I want is to search...
1
by: Prabhudhas Peter | last post by:
Hello, Need an easy way to Display the property values of an object (dynamically) ie I need to show the values of an Object in a rich text box. Background : We have a form, with a rich...
16
by: tyrfboard | last post by:
I've been searching for awhile now on how to remove duplicates from a table within an Access db and have found plenty of articles on finding or deleting duplicates. All I want to do is remove them...
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 ...
3
by: mkjets | last post by:
I have worked for hours on trying to find a solution and have not figured it out. I am working in Access 2003. I need to create a query that takes values from 1 table and displays them in...
27
by: MLH | last post by:
How can I turn the following into a make-table query? SELECT & " " & AS Recipient FROM tblVehicleJobs INNER JOIN tblAddnlOwnrs ON tblVehicleJobs.VehicleJobID = tblAddnlOwnrs.VehicleJobID WHERE...
2
by: scolivas | last post by:
Is there a way to automate this process? I have a query that finds the "Drop Offs" by doing an unmatch query against the hard table and the live table. I want to automatically pull these...
0
by: Steve Kirby | last post by:
You can't ... What you might try is: desc tabe1 This will list the columns in that table. You can select what you want to pull from that way.
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.