473,382 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

SQL Query

Write an update query to join the mail table with a table called mail2 where the email addresses match.Set Email field equal to 'X'.

create table mail(email varchar(50))
insert into mail values('sonia.sardana@yahoo.co.in')
insert into mail values('a.xzy@gmmail.com')


create table mail2(email varchar(50))
insert into mail2 values('a.xzy@gmmail.com')
insert into mail2 values('sardana.sonia@gmail.com')
select * from mail2

Final Query--
Update mail.email set email='X' where mail.email=mail2.email
Error is coming Invalid object name 'mail.email'. I want to update the entries in Mail Table.
Apr 9 '08 #1
7 1016
deric
92
Hi..
You need not specify the table's field in the Update statement.
http://msdn2.microsoft.com/en-us/library/aa260662(SQL.80).aspx

Expand|Select|Wrap|Line Numbers
  1. Update mail set email='X' where mail.email=mail2.email
  2.  
Apr 10 '08 #2
Delerna
1,134 Expert 1GB
Yes the basic syntax for update is
Expand|Select|Wrap|Line Numbers
  1. UPDATE NameOfTableToUpdate
  2.   SET NameOfField1ToUpdate=VaueForField1,
  3.       NameOfField2ToUpdate=ValueForField2,
  4.       .......etc
  5.  

so your error is coming from the mail.email in

Update mail.email set email='X' .........

it should be
Update mail set email='X' ........

as pointed out by the previous post

Also the where clause is not correct because the mail2 table is not setup to be used by the query
Apr 10 '08 #3
Delerna can u tell me what to write in the where clause.
If I write the foll.Query-
Update mail set email='X' where mail.email=mail2.email

Error is there-
The multi-part identifier "mail2.email" could not be bound.
Apr 10 '08 #4
Delerna
1,134 Expert 1GB
I am unsure what your intent is here.

What data is in table Mail2 ?
Are you intending that Mail2 has a list of emails that you want to update within the main Mail table.

In other words, out of all the records in Mail only update the ones that exist in Mail2.

Or are you intending to update the email field in the mail table to the email field in the mail2 table.

or is it something else.
The way to write it is dependent on your intent
Apr 11 '08 #5
Two tables are there Mail & Mail2. I want that if email matches in both the tables then update that all that entries in Mail Table to 'X'.
Apr 11 '08 #6
Delerna
1,134 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. UPDATE Mail
  2. SET Email='X'
  3. FROM Mail,Mail2
  4. WHERE Mail.Email=Mail2.Email
  5.  
Apr 11 '08 #7
Thx,I
t worked out.
Apr 12 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the...
29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
3
by: Harvey | last post by:
Hi, I try to write an asp query form that lets client search any text-string and display all pages in my web server that contain the text. I have IIS 6.0 on a server 2003. The MSDN site says...
4
by: Diamondback | last post by:
I have two tables, WIDGETS and VERSIONS. The WIDGETS table has descriptive information about the widgets while the VERSIONS table contains IDs relating to different iterations of those widgets...
14
by: Dave Thomas | last post by:
If I have a table set up like this: Name | VARCHAR Email | VARCHAR Age | TINYINT | NULL (Default: NULL) And I want the user to enter his or her name, email, and age - but AGE is optional. ...
0
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
4
by: Stan | last post by:
I am using MS Office Access 2003 (11.5614). My basic question is can I run a query of a query datasheet. I want to use more that one criteria and can not get that query to work. I thought I...
6
by: jsacrey | last post by:
Hey everybody, got a secnario for ya that I need a bit of help with. Access 97 using linked tables from an SQL Server 2000 machine. I've created a simple query using two tables joined by one...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.