Solved

sql problem

Posted on 2012-03-24
10
244 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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 videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

759 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

19 Experts available now in Live!

Get 1:1 Help Now