Solved

SQL Select * from

Posted on 2016-09-09
6
29 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:Wass_QA
  • 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
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 

Author Comment

by:Wass_QA
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:Wass_QA
ID: 41791604
Thank you very much guys.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
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.

707 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

12 Experts available now in Live!

Get 1:1 Help Now