Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Exporting select from two MySQL tables to one JSON file

$
0
0

How can I run a query against a database with two tables client and appointment to out put JSON like this:

{"id": "1","app1": null,"app2": null,"app3":["cname": "John","clastname": "Doe","cemail": "john@doe.com","cphone": "604",    ],"app4":["cname": "Mark","clastname": "Martini","cemail": "mark@martini.com","cphone": "778",    ]}

As you can see I need to get null when the appx fields are null and load with client table data where the appx = cilentid

Here are my tables

CREATE TABLE Client (id INT(6),cname VARCHAR(30) NOT NULL,clastname VARCHAR(30) NOT NULL,cemail VARCHAR(50),cphone VARCHAR(50));INSERT INTO Client     (`id`, `cname`, `clastname`, `cemail`, `cphone`) VALUES    (25, 'John', 'Doe', 'john@doe.com', '604'),   (60 ,'Mark', 'Martini', 'mark@martini.com', '778') ; CREATE TABLE appointments (id INT(6),app1 INT(6)  DEFAULT NULL,app2 INT(6)  DEFAULT NULL,app3 INT(6) DEFAULT NULL,app4 INT(6) DEFAULT NULL);INSERT INTO appointments     (`id`, `app1`, `app2`, `app3`, `app4`) VALUES    (1,null,null,null,60),   (2,25,null,null,null) ;

enter image description here


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>