Solved

sql statement to select and drop

Posted on 2016-11-03
13
42 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
  • 7
  • 6
13 Comments
 
LVL 24

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 24

Expert Comment

by:Pawan Kumar
ID: 41871873
Sorry didnt get you?
0
 

Author Comment

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

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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 24

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 24

Accepted Solution

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

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

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 24

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

920 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

16 Experts available now in Live!

Get 1:1 Help Now