Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Column update from one Table to another based on a ID match #111

Open
ahmedmohiduet opened this issue Aug 10, 2023 · 2 comments
Open

Column update from one Table to another based on a ID match #111

ahmedmohiduet opened this issue Aug 10, 2023 · 2 comments

Comments

@ahmedmohiduet
Copy link

ahmedmohiduet commented Aug 10, 2023

How can I Column update from one Table to another based on a ID match?

I have one equery:
csvq 'update nullbatches join file on nullbatches.Inv_date=file.Inv_date set nullbatches.Btc_no = file.Btc_no where file.P_code!=9 and file.P_code!=42 and nullbatches.P_code!=9 and nullbatches.P_code!=42' ( my csvs: nullbatches.csv, file.csv)

Which says: [L:1 C:20] syntax error: unexpected token "join"

Is it doable?

@ondohotola
Copy link

ondohotola commented Aug 10, 2023

I had a similar issue recently and got around it by something like

UPDATE nullbatches
SET nullbatches.Btc_no = (
   SELECT file.Btc_no 
   FROM file 
   WHERE nullbatches.Inv_date = file.Inv_date
)

@mithrandie
Copy link
Owner

You can also write the query like this.

UPDATE n
   SET n.Btc_no = f.Btc_no
  FROM nullbatches n
       JOIN file f
         ON f.Inv_date = n.Inv_date
 WHERE NOT f.P_code IN (9, 42)
   AND NOT n.P_code IN (9, 42);

cf. https://mithrandie.github.io/csvq/reference/update-query.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants