Solved

sql statement to select and drop

Posted on 2016-11-03
13
50 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 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
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.

 

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

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

Title # Comments Views Activity
Mysql Crashing Intermittently 16 113
change database name 2 36
Very Large data in MYSQL 7 73
Wifi connection to laptop without router windows 10 11 37
Foreword This article was written many years ago, in the days when PHP supported the MySQL extension (http://php.net/manual/en/function.mysql-connect.php).  Today (http://php.net/manual/en/migration70.removed-exts-sapis.php) you would not use MySQL…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

807 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