Different Methods of Joining Tables in SQLike

Struggling with creating a two-level JOIN in SQLike, currently stuck at the one level JOIN.

The source tables are JSONs:

var placesJSON=[{"id":"173","name":"England","type":"SUBCTRY"},{"id":"580","name":"Great Britain","type":"CTRY"},{"id":"821","name":"Southern England","type":"REG"},{"id":"822","name":"Northern England","type":"REG"},{"id":"831","name":"Southwest England","type":"REG"},{"id":"832","name":"Southeast England","type":"REG"},{"id":"833","name":"Western Midlands","type":"REG"},{"id":"834","name":"Eastern Midlands","type":"REG"},{"id":"889","name":"Eastern England","type":"REG"},{"id":"937","name":"Central Southern England","type":"REG"}];
var relationsJSON=[{"son":"173","father":"580"},{"son":"821","father":"173"},{"son":"822","father":"173"},{"son":"831","father":"173"},{"son":"832","father":"173"},{"son":"833","father":"173"},{"son":"834","father":"173"},{"son":"889","father":"173"},{"son":"937","father":"173"}]; 

This is the MySQL equivalent query:

SELECT DISTINCT p.id, p.name, p.type, r.son, r.father, f.name  
FROM places p
JOIN places_relations r ON p.id=r.son
JOIN places f ON f.id=r.father

The first JOIN works well:

SQLike.q({
   SelectDistinct: ['p_id', 'p_name', 'r_son' ,'p_type', 'r_father'],
   From: {p:placesJSON},
   Join: {r:relationsJSON},  
   On: function(){return this.p.id==this.r.son}
})

When attempting to add the second JOIN, no results are returned. The attempted syntax:

SQLike.q({
   SelectDistinct: ['p_id', 'p_name', 'r_son' ,'p_type', 'r_father', 'f_name'],
   From: {p:placesJSON},
   Join: {r:relationsJSON},  
   On: function(){return this.p.id==this.r.son},
   Join: {f:placesJSON},  
   On: function(){return this.f.id==this.r.father}

Any suggestions on how to solve this issue?

Answer №1

If you find that the On and Join properties are being overridden, it may be due to lack of adequate documentation and unreadable code. You could experiment with using implicit join or explore the following approach:

Join: {r:relationsJSON, f:placesJSON},  
On: function(){return this.p.id==this.r.son && this.f.id==this.r.father; }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for Sending Props While Utilizing CSS Modules

I've been working with a button component that utilizes the Tailwindcss framework and css modules for some extra styling. It currently looks like this, incorporating template literal to integrate the red background styling. CSS Module: .red { back ...

Breaking down this JSON (array)

Greetings! I have a section of JSON data that requires parsing, and I have condensed it for better visibility. [ { "trends": [ { "name": "#CyberMonday", "url": "https://twitter.com" }, { "name": "#Bl ...

Running code sequentially in a Node.js controller

Recently delved into the world of Node.js, and I'm currently tackling the challenge of running this code synchronously in my controller. Quest.js async function create(req, res, next) { const formValue = req.body['form']; ...

What is the mechanism by which a Node.js server handles incoming requests?

Suppose I am working with this code snippet. I am using ExpressJS, although the server part doesn't seem much different from vanilla Node.js. var express=require('express'); var settings=JSON.parse(fs.readFileSync('settings.json' ...

Is it possible to dispatch actions from getters in Vuex?

Fiddle : here Currently, I am in the process of developing a web application using Vue 2 with Vuex. Within my store, I aim to retrieve state data from a getter. My intention is for the getter to trigger a dispatch and fetch the data if it discovers that t ...

What is the best way to use multiple encoding types when sending data via a POST method in Node.js?

My current challenge involves sending a combination of name and description text data alongside a video file. Unfortunately, I've encountered an issue where I can only send either the video or the text, but not both simultaneously. Below is the code ...

Oops! It seems like there was an issue trying to access properties that are undefined while reading 'pipe' in Angular12

I encountered an issue when trying to send an AJAX request, displaying the following error message: ERROR TypeError: Cannot read properties of undefined (reading 'pipe') This error occurred in the ajax-loader.interceptor.ts class export class A ...

Color in the diamond shape only to a designated height

I am in search of a unique diamond shape that allows me to fill the color up to a specific height based on an attribute or variable provided. https://i.stack.imgur.com/62U6h.png. I attempted creating the diamond shape and initially considered placing it ...

Tips for automatically filling in fields when a button is clicked in a React application

I'm attempting to pre-fill the form fields that are duplicated with data from already filled fields. When I click the "Add Fields" button, new fields are replicated, but I want them to be pre-populated with data from existing fields. How can I access ...

External vendor scripts such as JavaScript and jQuery are not functioning properly after being rendered in a ReactJS environment

I am currently developing a frontend web app using ReactJS. I obtained a template from W3layout that is built with HTML5, CSS3, and custom JS files, along with various third-party/vendor plugins like nice-select, bootstrap, slik, owl-carousel, etc. Despit ...

Tips for extracting nested JSON using Python and the Pandas library

I need help parsing the response I received from an API. The format of the response is as follows: jsn= " {'headers': ['deviceCategory', 'eventName', 'eventCount', 'eventValue'], 'rows': [[ ...

Launching numerous websites in separate browser tabs using the window.open function

I have a code snippet that opens one tab pointing to a website, but I need it to open two. For example: www.google.com and www.yahoo.com Currently, it only works with one site in the code: window.open("https://www.google.com"); but not when bot ...

Trouble with React Native ListView Item Visibility

I'm currently working on integrating the React Native <ListView /> component with the <List /> and <ListItem /> components from React Native Elements. However, I seem to be facing an issue where the <ListItem /> component is no ...

Extract different properties from an object as needed

Consider the following function signature: export const readVariableProps = function(obj: Object, props: Array<string>) : any { // props => ['a','b','c'] return obj['a']['b']['c'] ...

Is there a way to trigger the opening of a new file or page when a CSS animation comes to an end?

Is there a way to delay the loading of a function or page until after an animation has finished running in JavaScript, HTML, and CSS only? For instance, I'd like to run an animation first and then have a different website or content load afterwards fo ...

Understanding the mechanism of callback function in NodeJS within the context of routes and controllers

Trying to grasp the concept of callbacks and puzzled by the recurring issue TypeError: callback is not a function Here's my router setup: // getPriceRouter.js router.post('/getPrice', function(req, res) { priceController.getPrice(req, ...

How to avoid mistakes with GSon in Java (avoiding null pointer exceptions)

I'm attempting to extract the number of search results from a Google query string. public class Utils { public static int getGoogleHits(String query) throws IOException { String googleAjax = "http://ajax.googleapis.com/ajax/services/sear ...

The requested method could not be located: 'System.Object Newtonsoft.Json.Linq.JToken.ToObject(System.Type)'

We are facing an issue with our MVC project using Json.net that is running smoothly on all developers' systems except for the one with the new Windows 8.1 operating system. How can we troubleshoot and identify the root cause of this "method not found" ...

Exploring the capabilities of xhr2 using pure javascript

Currently, I am attempting to utilize xhr2 in order to read through a json file. Despite my efforts in researching various methods to accomplish this task, none have proved successful thus far. The function featured below my require statements is the one t ...

Navigating through the complexities of scoping in JavaScript when integrating Node.js

Currently, I am working on an express.js application without using mongoose. My goal is to create a function that can handle calls to MongoDB, pass parameters to it, and retrieve data from the database. However, I have encountered a problem with the foll ...