sql command question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sql command question
# 1  
Old 09-17-2008
sql command question

Hi,

Table1
======
Code1
Field1

Table2
======
Code1
Field1

Would anyone be able to help me know what's the best sql command to delete the entry in Table1 if its Code1-Field1 combination is already existing in Table2.

I used this one -
delete from Table1 where Code1 in (select Code1 from Table2)
and Field1 in (select Field1 from Table2)

But this one will delete the entry even if its not exactly the Code1-Field1 combo, as long as both Code1 matches and Field1 exists in any of the rows in Table2 right?

Thanks in advance.
# 2  
Old 09-17-2008
delete from table1 where code1||field1 in (select code1||field1 from table2);
try this

Last edited by vidyadhar85; 09-17-2008 at 02:55 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Storing multiple sql queries output into variable by running sql command only once

Hi All, I want to run multiple sql queries and store the data in variable but i want to use sql command only once. Is there a way without running sql command twice and storing.Please advise. Eg : Select 'Query 1 output' from dual; Select 'Query 2 output' from dual; I want to... (3 Replies)
Discussion started by: Rokkesh
3 Replies

2. Shell Programming and Scripting

How to get sql command with output in files?

I tried executing set of queries from shell script but not able to capture the input query in the log file,but the input query is not displayed along with output. Only the outputs are being captured in the log file. Is there a way to capture the input query along with the corresponding input?? (8 Replies)
Discussion started by: pallvi_mahajan
8 Replies

3. Shell Programming and Scripting

Shell Scripting question with SQL

hey i have to connect to sql through shell script , then store the value of the query in a variable and then compare it after some time after running a process. i have used this code but it is not working. #!/bin/sh Val = (sqlplus -s rte/rted2@rel76d2 <<! SELECT MAX(STAT_ID) FROM CVT_STATS;... (3 Replies)
Discussion started by: ramsavi
3 Replies

4. UNIX for Dummies Questions & Answers

Help Command in SQL LOADER

Which is the UNIX command to get the SQL Loader Help??:confused: (1 Reply)
Discussion started by: venkatesh sunil
1 Replies

5. SuSE

my SQL Info command

Is there a command that will output all mysql details. eg. host name, port etc? Cheers Paul (1 Reply)
Discussion started by: runnerpaul
1 Replies

6. Programming

Simple SQL question!

Hi all, I would like to display more values of different tables in one row. The issue is that I want to display more values from the same column! exp. Table1 id | col1 ---------- 1 val1 2 val2 Table2 id | col2 ----------- 1 val2 2 val3 3 val4 (2 Replies)
Discussion started by: research3
2 Replies

7. UNIX for Advanced & Expert Users

Need sybase sql command help

Guys, My question is on the Sybase sql query, command 'sp_help' shows me list of all the tables. but I can not view them page by page. So is there any command to view them page by page as in our unix 'ls | less'. and one more thing command/procedure to store output into the file. Any... (4 Replies)
Discussion started by: jagdish.machhi@
4 Replies

8. Shell Programming and Scripting

Sorry question on SQL

Experts, I need small help in oracle. I am just putting this question here because i think there are SQL geniuses here as well as UNIX. I have a string that contains the First name, Middle name and last name in one field in the table in Oracle. I need to extract each one of them... (5 Replies)
Discussion started by: dsravan
5 Replies

9. Shell Programming and Scripting

sql insert command

Hi, sqlplus -s / <<EOF > /dev/null insert into table1 (a1, a2, a3) values ('a',1,'b'); commit; EOF in the above code can i pass the values to the insert command from shell script like this: insert into table1 (a1, a2, a3) values ('$a',$b,'$c'); If yes, how is it passed?? Any... (2 Replies)
Discussion started by: abey
2 Replies

10. Windows & DOS: Issues & Discussions

ms sql command reference

does somebody know where i can find command reference for mssql? i tried to search via google and it does help me that much. maybe someone can refer me a site. thank you very much. (2 Replies)
Discussion started by: inquirer
2 Replies
Login or Register to Ask a Question