Split a SQL query in different text boxes

I made separate queries on a SQL view, and put the received data into some text boxes.
It works, but, if I want to get more data, it seems to me silly to use a separate query for each data I want to retreive.
What I'm trying to do, is to write a single query, then split the result, and put it into separates text boxes.
Has someoune any hints?

Below is my current flow

[{"id":"c8954a23.36cbe8","type":"inject","z":"cbdd8276.7b74","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"1","x":120,"y":200,"wires":[["2d44cc0b.df7c9c","2b9a0a15.d55286","9ca88b41.b01528"]]},{"id":"d884499.3863d38","type":"mysql","z":"cbdd8276.7b74","mydb":"f8c4b444.c34a78","name":"get plant name","x":560,"y":120,"wires":[["15c9a293.665d55"]]},{"id":"2d44cc0b.df7c9c","type":"function","z":"cbdd8276.7b74","name":"sql name query","func":"msg.topic = \"select name from view_plant\"\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":120,"wires":[["d884499.3863d38"]]},{"id":"2c0ef108.a82516","type":"ui_text","z":"cbdd8276.7b74","group":"d9b023d.45ee1e","order":1,"width":0,"height":0,"name":"","label":"Plant name","format":"{{msg.payload}}","layout":"col-center","x":1050,"y":120,"wires":[]},{"id":"d3346014.5a741","type":"mysql","z":"cbdd8276.7b74","mydb":"f8c4b444.c34a78","name":"get plant owner","x":580,"y":180,"wires":[["2470d614.03659a"]]},{"id":"2b9a0a15.d55286","type":"function","z":"cbdd8276.7b74","name":"sql owner query","func":"msg.topic = \"select owner from view_plant\"\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":180,"wires":[["d3346014.5a741"]]},{"id":"2470d614.03659a","type":"split","z":"cbdd8276.7b74","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"topic","x":750,"y":180,"wires":[["c4875804.bc45a"]]},{"id":"c4875804.bc45a","type":"split","z":"cbdd8276.7b74","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":890,"y":180,"wires":[["a821eaa3.09e088"]]},{"id":"a821eaa3.09e088","type":"ui_text","z":"cbdd8276.7b74","group":"69bcb450.363e94","order":1,"width":0,"height":0,"name":"","label":"Owner","format":"{{msg.payload}}","layout":"col-center","x":1030,"y":180,"wires":[]},{"id":"857095fe.3af3a8","type":"mysql","z":"cbdd8276.7b74","mydb":"f8c4b444.c34a78","name":"get location","x":570,"y":260,"wires":[["187b07c5.7b94b8"]]},{"id":"9ca88b41.b01528","type":"function","z":"cbdd8276.7b74","name":"sql location query","func":"msg.topic = \"select location from view_plant\"\nreturn msg;","outputs":1,"noerr":0,"x":350,"y":260,"wires":[["857095fe.3af3a8"]]},{"id":"187b07c5.7b94b8","type":"split","z":"cbdd8276.7b74","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"topic","x":750,"y":260,"wires":[["1d4cb57f.06374b"]]},{"id":"1d4cb57f.06374b","type":"split","z":"cbdd8276.7b74","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":890,"y":260,"wires":[["e49a6db6.cff48"]]},{"id":"e49a6db6.cff48","type":"ui_text","z":"cbdd8276.7b74","group":"3ced5313.d6ff2c","order":1,"width":0,"height":0,"name":"","label":"Location","format":"{{msg.payload}}","layout":"col-center","x":1040,"y":260,"wires":[]},{"id":"15c9a293.665d55","type":"split","z":"cbdd8276.7b74","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"topic","x":750,"y":120,"wires":[["3e87f1bc.e9648e"]]},{"id":"3e87f1bc.e9648e","type":"split","z":"cbdd8276.7b74","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":890,"y":120,"wires":[["2c0ef108.a82516"]]},{"id":"f8c4b444.c34a78","type":"MySQLdatabase","z":"","host":"127.0.0.1","port":"3306","db":"mdb","tz":""},{"id":"d9b023d.45ee1e","type":"ui_group","z":"","name":"Group 1","tab":"7b129b8e.3ae0fc","order":1,"disp":false,"width":"4","collapse":false},{"id":"69bcb450.363e94","type":"ui_group","z":"","name":"Group 3","tab":"7b129b8e.3ae0fc","order":2,"disp":false,"width":"6","collapse":false},{"id":"3ced5313.d6ff2c","type":"ui_group","z":"","name":"Group 8","tab":"7b129b8e.3ae0fc","order":6,"disp":false,"width":"6","collapse":false},{"id":"7b129b8e.3ae0fc","type":"ui_tab","z":"","name":"Configurator","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

it seems to me you should start by looking at an SQL tutorial like https://www.w3schools.com/sql/

Maybe I've not been clear...
I know how to request multiple values from a sql table. :slightly_smiling_face:

I don't know how to handle the result, and split it in different text boxes.

Rather than branching out on the inject node, have you thought of branching after the query returns? You can use a change node to move the contents of the payload around.

Say you do a select * from view_plant that will return (in msg.payload) an array of every row in the database. Each array occurrence (i.e. msg.payload[0], msg.payload[1]...msg.payload[n]) will be an object an all the column's in each database row will be included. You can then address each element as you need it. example msg.payload[0].name etc

try this first in your function node, then split it by object name. if you do not yet have a timestamp collumn in your database, ADD IT!!
msg.topic = "select name, owner, location from view_plant group by timestamp desc"

That worked! Brilliant!

I used several Change nodes, one for each column of the table, in which I moved msg.payload[0].name, .owner, ecc.., to msg.payload, and then that payload into the text box.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.