Skip to content
Advertisement

How to shorten mysql join query to avoid manual typing of each row?

I have a table that gets new rows for eg. I’d add more than 100 features like phone_number, username to the processed_donors to this table very soon.IS it possible to simplify this json_object(****) so It’s not an evergrowing list? Some way to use pandas+python, select * etc?

Advertisement

Answer

I think you could do this in two steps.

First, you need to get all the columns of the processed_donors table. Then you can use this result to build your query string.

Note that I don’t have a mysql DB running here, so I can’t check if that’s the correct way how to build the column_names, but I hope you get the idea. You can use the same process to build the json_object for b and then build a query string.

Please keep in mind that normally, creating a SQL query manually like this is a bad idea do to SQL injection vulnerabilities, but I presume there’s no user input involved here and you control the names of the columns, so it should be fine.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement