Solved

join not working!!

Posted on 2004-04-02
6
127 Views
Last Modified: 2013-12-24
this simple query is supposed to add records from itemlist table into orderhistory table, can anyone tell me why it does not work anymore now that i have moved the db from access to sql

            <cfquery datasource="#Application.DataSource#" username="x" password="x" name="test3">
      UPDATE itemlist
      LEFT JOIN orderhistory ON itemlist.itemlistoid = orderhistory.itemlistoid
      SET orderhistory.itemlistoid = itemlist.itemlistoid, orderhistory.useroid = itemlist.useroid, orderhistory.cartoid = itemlist.cartoid, orderhistory.itemoid = itemlist.itemoid, orderhistory.itemlistselection = itemlist.itemlistselection, orderhistory.itemquantity = itemlist.itemquantity;
      </cfquery>
0
Comment
Question by:finnstone
6 Comments
 
LVL 5

Expert Comment

by:jayeshshah
ID: 10746558
change the update statement to

UPDATE itemlist
SET orderhistory.itemlistoid = itemlist.itemlistoid, orderhistory.useroid = itemlist.useroid, orderhistory.cartoid = itemlist.cartoid, orderhistory.itemoid = itemlist.itemoid, orderhistory.itemlistselection = itemlist.itemlistselection, orderhistory.itemquantity = itemlist.itemquantity
from itemlist
     LEFT JOIN orderhistory ON itemlist.itemlistoid = orderhistory.itemlistoid


Regards

JBS
0
 
LVL 11

Accepted Solution

by:
hart earned 200 total points
ID: 10746563
i don't see u inserting records, u r updating the table..

just try the following query

insert into orderhistory (itemlistoid, useroid, cartoid, itemoid , itemlistselection , itemquantity)
as select itemlistoid, useroid, cartoid, itemoid , itemlistselection , itemquantity from itemlist

Regards
Hart
0
 
LVL 35

Assisted Solution

by:mrichmon
mrichmon earned 150 total points
ID: 10758281
Actually you can write it even simpler as :

INSERT INTO orderhistory SELECT itemlistoid, useroid, cartoid, itemoid, itemlistselection, itemquantity FROM itemlist

which will insert all of the columns from itemlist into the orderhistory table
You don't need to specify fields unless there are fields that do not match.
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 11

Expert Comment

by:hart
ID: 10774821
finnstone : did it work out :-)
0
 
LVL 6

Assisted Solution

by:PE_CF_DEV
PE_CF_DEV earned 150 total points
ID: 10775051
If you want to update orderhistory then maybe this:

Update orderhistory <!--- Not itemlist --->
SET orderhistory.itemlistoid = itemlist.itemlistoid, orderhistory.useroid = itemlist.useroid, orderhistory.cartoid = itemlist.cartoid, orderhistory.itemoid = itemlist.itemoid, orderhistory.itemlistselection = itemlist.itemlistselection, orderhistory.itemquantity = itemlist.itemquantity
From itemlist  LEFT JOIN orderhistory ON itemlist.itemlistoid = orderhistory.itemlistoid

HTH
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 10793550
finnstone,

Did any of these solutions work for you?
0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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