Solved

sql statement to select and drop

Posted on 2016-11-03
13
33 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 18

Expert Comment

by:Pawan Kumar Khowal
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 18

Expert Comment

by:Pawan Kumar Khowal
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 18

Expert Comment

by:Pawan Kumar Khowal
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 18

Expert Comment

by:Pawan Kumar Khowal
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 18

Accepted Solution

by:
Pawan Kumar Khowal 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 18

Expert Comment

by:Pawan Kumar Khowal
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 18

Expert Comment

by:Pawan Kumar Khowal
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Loading csv or delimited data files to MySQL database is a very common task frequently questioned about and almost every time LOAD DATA INFILE comes to the rescue. Here we will try to understand some of the very common scenarios for loading data …
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

13 Experts available now in Live!

Get 1:1 Help Now