Solved

SQL Select * from

Posted on 2016-09-09
6
36 Views
Last Modified: 2016-09-09
Hello,
Each order in my table has more than one note.
I need to select only orders that don't have a note that starts with 'Billing: '

Select order from OrderNotes where text.....

attached is a sample of what the select would look like.
attached highlighted orders should not be included. (Because they have a note that starts with 'Billing: '
The not highlighted is what I need. (I only need the order) --- Example Column 'k'

Your help is appreciated.
Sample.xlsx
0
Comment
Question by:W.E.B
  • 2
  • 2
  • 2
6 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 41791548
quick try:

select a.* from OrderNotes a
left join
(
select [Order] from OrderNotes
where [text] like '%Billing%'
group by [Order]
) b
on a.[Order] = b.[Order]
where b.[Order] is null

Open in new window

0
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 250 total points
ID: 41791551
or to be more precise:

select a.[Order] from OrderNotes a
left join
(
select [Order] from OrderNotes
where [text] like '%Billing%'
group by [Order]
) b
on a.[Order] = b.[Order]
where b.[Order] is null
group by a.[Order]

Open in new window

0
 
LVL 65

Assisted Solution

by:Jim Horn
Jim Horn earned 250 total points
ID: 41791552
<knee-jerk, minute-fast answer>
Select DISTINCT on.order
from OrderNotes on 
   LEFT JOIN (
      SELECT DISTINCT order
      FROM OrderNotes
      where LEFT(text, 8) = "Billing:") onb ON on.Order = onb.Order
WHERE onb.Order IS NULL

Open in new window

0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

by:W.E.B
ID: 41791592
Thank you ,
Ryan Select seems to work, I'm trying it now.
Jim, I'm not getting any results back with your select.

thanks,
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 41791596
Typo, <> should have been =.   Corrected in original post.
0
 

Author Closing Comment

by:W.E.B
ID: 41791604
Thank you very much guys.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now