Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Select * from

Posted on 2016-09-09
6
Medium Priority
?
56 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 54

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 54

Accepted Solution

by:
Ryan Chong earned 1000 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 66

Assisted Solution

by:Jim Horn
Jim Horn earned 1000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 66

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

782 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