• 0

MYSQL INSERT JOIN?


Question

hello I want a simple way of writing this >>

insert into table
LEFT JOIN `otherTable`
on otherTable.`field`='value'
AND otherTable.`otherfield`='anotherValue'
(`column`, `column`, `column`)VALUES('data',otherTable.`data`,'anotherValue')

I know this does not work, but you can see the logic i am trying to achieve... but I was wondering if there is a simple way to do this..I know of many ways (selecting the data first, nested select statement and so forth) but while writing a new script I thought hmm there has to be an easier cleaner way to do this.... so I thought I would ask neowin for future reference

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0
INSERT INTO table (`column`, `column`, `column`)
SELECT
'Data',
otherTable.`data`,
'anotherValue'
FROM otherTable
WHERE otherTable.`field` = 'value'
AND otherTable.`otherfield` = 'anotherValue'

Might not be 100% accurate, written in my head whilst lunching on a sandwich but should give you the gist of there you need to go ;)

Link to comment
Share on other sites

  • 0
INSERT INTO table (`column`, `column`, `column`)
SELECT
'Data',
otherTable.`data`,
'anotherValue'
FROM otherTable
WHERE otherTable.`field` = 'value'
AND otherTable.`otherfield` = 'anotherValue'

Might not be 100% accurate, written in my head whilst lunching on a sandwich but should give you the gist of there you need to go ;)

 

ahh ok thanks Il give that a look....i wasnt to far off the mark

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.