Solved

sql problem

Posted on 2012-03-24
10
257 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
query execution hang 5 28
MS SQL Merging data from table into another table 1 32
Get the latest status 8 30
Help in Bulk Insert 9 30
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
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…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

785 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