?
Solved

sql statement to select and drop

Posted on 2016-11-03
13
Medium Priority
?
63 Views
Last Modified: 2016-11-05
Hi All,

I can use the string below to get the result from the TABLE, TABLE_NAME1='Tree'

Now I need to expand the select to add AND condition (TABLE_NAME2='Apple Tree: 3')

TABLE_NAME2 contain many string for each row of data, "Apple Tree: 3" should include condition

after confirm the result, I need to drop the table match the result.

Please help to with the select and drop statement

SELECT * FROM 
[DB].[dbo].[TABLE]
WHERE TABLE_NAME1 = 'Tree'

Open in new window

0
Comment
Question by:Julio Jose
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41871856
Something like this is needed ,  Drop is not required in this case only SELECT is needed.

SELECT * FROM
[DB].[dbo].[TABLE1]  a
INNER JOIN [DB].[dbo].[TABLE2]  b
ON a.col = b.col <<Matching columns from both the tables>>
WHERE a.TABLE_NAME1 = 'Tree'
AND b.TABLE_NAME2='Apple Tree: 3'

Hope it helps !!
0
 

Author Comment

by:Julio Jose
ID: 41871872
Can you confirm again, that is no TABLE2
0
 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41871873
Sorry didnt get you?
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

Author Comment

by:Julio Jose
ID: 41871887
That is no  [DB].[dbo].[TABLE2]  the data from the single table
0
 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41871904
Okies, Try.. this

SELECT *
FROM
[DB].[dbo].[TABLE]
WHERE
         TABLE_NAME1 = 'Tree'
AND TABLE_NAME2 = 'Apple Tree: 3'

OR this

SELECT *
FROM
[DB].[dbo].[TABLE]
WHERE
         TABLE_NAME1 = 'Tree'
OR   TABLE_NAME2 = 'Apple Tree: 3'
0
 

Author Comment

by:Julio Jose
ID: 41871925
TABLE_NAME1 condition work, the TABLE_NAME2 not work

TABLE_NAME2 = 'Apple Tree: 3'

That is long string in the TABLE_NAME2, can the statement use matching to match the relevant string.

 example
like eewqfewfsc |||| 1213123 Apple Seed:   000  Apple Tree:   3 dfasfasfasfsafsaf
0
 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41871927
Okies, Try.. this  LIKE

SELECT *
FROM
[DB].[dbo].[TABLE]
WHERE
         TABLE_NAME1 = 'Tree'
AND TABLE_NAME2  LIKE  '%Apple Tree: %3%'

OR this

SELECT *
FROM
[DB].[dbo].[TABLE]
WHERE
         TABLE_NAME1 = 'Tree'
OR   TABLE_NAME2  LIKE  '%Apple Tree: %3%'
0
 

Author Comment

by:Julio Jose
ID: 41871933
Thanks.

How can I get the result exclude Apple Tree: 3
0
 
LVL 29

Accepted Solution

by:
Pawan Kumar earned 2000 total points
ID: 41871936
Try...

SELECT *
FROM
[DB].[dbo].[TABLE]
WHERE
         TABLE_NAME1 = 'Tree'
AND TABLE_NAME2  NOT LIKE  '%Apple Tree: %3%'
0
 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41871959
Hi Julio,
Is it done :)?

Regards,
Pawan
0
 

Author Comment

by:Julio Jose
ID: 41875169
NOT LIKE or LIKE return false positive, Apple 2/3/4 also include in the output, what other way for accurate output result?
0
 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41875190
Select * from table where table_name1 = 'tree'

Except

Select * from table where table_name1 = 'tree' and table_name2 like '%Apple Tree:%3%'

Hope it helps !!
0
 

Author Closing Comment

by:Julio Jose
ID: 41875318
Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

764 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