Solved

sql statement to select and drop

Posted on 2016-11-03
13
52 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 28

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 28

Expert Comment

by:Pawan Kumar
ID: 41871873
Sorry didnt get you?
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

Author Comment

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

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 28

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 28

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 28

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 28

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

740 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