Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

sql problem

Posted on 2012-03-24
10
Medium Priority
?
287 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
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

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.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

722 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