Solved

sql problem

Posted on 2012-03-24
10
261 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Table where row act as column 11 67
Problems creating account in AD with Powershell, data from SQL 57 46
SQL Throw Error 7 30
SQL Server 2008 Std. License Key owner or vendor 4 53
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

680 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