Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

sql problem

Posted on 2012-03-24
10
Medium Priority
?
296 Views
Last Modified: 2012-04-01
#1064 - You have an error in your SQL syntax; check the manual

UPDATE member SET member.advertID=ads.ID  FROM member,ads  WHERE member.member_id=ads.memID AND type='e'

Why is this happening?
0
Comment
Question by:mmguide
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 12

Expert Comment

by:sachitjain
ID: 37760537
Try this
update x set x.advertID  = y.ID
from member x inner join ads y on x.member_id = x.memID and type='e'
0
 

Author Comment

by:mmguide
ID: 37760724
Not sure I understand the x and y. Am I meant to use this as is? If so there is still a 1064 error
0
 
LVL 12

Expert Comment

by:NormanMaina
ID: 37760777
Just remove the comma in your original code.

FROM member,ads
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 12

Expert Comment

by:NormanMaina
ID: 37760786
I would rewrite your query:

UPDATE member SET member.advertID=ads.ID  FROM member inner join ads  WHERE member.member_id=ads.memID AND type='e'

Open in new window


or even better:


UPDATE mem SET mem.advertID=ads.ID  FROM member mem inner join ads on mem.member_id=ads.memID Where type='e'
0
 
LVL 9

Expert Comment

by:macarrillo1
ID: 37760857
The x and the y that @sachitjain was using in the first comment are alias for the tables.

So instead of:

update member
set member.advertID  = ads.ID
from member inner join ads
on member.member_id = ads.memID
Where type='e'

you could rewrite your query to look like this:

update M
set M.advertID  = A.ID
from member M inner join ads A
on M.member_id = A.memID
Where type='e'

I used M and A instead of X and Y, because it is easier for me to relate M to member and A to Ads.  Using Alias for tables often simplifies the SQL and makes it more readable.
0
 
LVL 12

Expert Comment

by:sachitjain
ID: 37761020
Thanks Macarrilo1. You explained what I meant.
0
 
LVL 12

Expert Comment

by:kselvia
ID: 37761129
Actually even though converting to ANSI-SQL joins, or using aliases makes the query easier to read and understand, there is nothing wrong with your query.  The example below works just fine, using the exact syntax you have;

create table member (member_id int, advertid int null, type char(1))
create table ads (memid int,  id int )
insert member (member_id, type) select 1, 'e'
insert ads select 1,5

select * from member

UPDATE member SET member.advertID=ads.ID  FROM member,ads  WHERE member.member_id=ads.memID AND type='e'

select * from ads
select * from member

member_id   advertid    type
----------- ----------- ----
1           NULL        e

memid       id
----------- -----------
1           5

member_id   advertid    type
----------- ----------- ----
1           5           e


But your error #1064 appears to be a MySQL generated error, according to Google, not a MS Sql Server.  If this were SQL Server, the cause would have to be a trigger on the member table.

Since this appears to by My SQL, I suspect the problem is that "type" is a MySQL reserved word.  I'm not a MySql user, but you might try changing type to [type] (if MySql supports that)

UPDATE member SET member.advertID=ads.ID  FROM member,ads  WHERE member.member_id=ads.memID AND [type]='e'
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 37762907
Since your tag indicates this is a MySQL question and nothing to do with SQL Server, you may want to have this quetion moved to a more appropriate topic area such as (you guessed it):
http://www.experts-exchange.com/Database/MySQL/
0
 

Accepted Solution

by:
mmguide earned 0 total points
ID: 37771354
Hi All,
Thanks for your help but this seems to be an inherent sql Mamp server issue that has been wasting much time and I have decided to circumvent this by using a php script .
Not ideal but the only solution for sanity and time-efficiency.
0
 

Author Closing Comment

by:mmguide
ID: 37792629
Not a solution to this problem but a software issue rather than scripting.
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

773 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