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

mastering the chrome api within your redux-saga workflow

Currently, I'm working on creating a 'get_current_url' function using redux-saga in my project involving a Chrome extension built with React.js. In order to obtain the current URI, I need to utilize the chrome.tabs.query API. Below is the sn ...

JavaScript allows users to create a single string by merging multiple strings positioned at various points

Let's say we have 3 strings: s1 = "ab", s2 = "cd", s3 = "ef". The task is to form a new string by merging s1, s2, and s3. The twist here is that the user has the freedom to choose the positions of these 3 strings. For example: s1 - position 3; s2 - ...

Avoid retrieving data during the fetching process

I have been working on an application that utilizes Redux for state management. Furthermore, I have been using the native fetch method to fetch data. return fetch("https://dog.ceo/api/breeds/image/random").then(res => res.json()); Within my React co ...

Tips for customizing the IconButton appearance in material-ui

While Material-ui offers a default icon button, I am interested in customizing its design to resemble this: IconButton design needed Could you please advise me on how to make this change? Thank you. ...

Securing data in AngularJS $http.post requests: Best practices

While working on $http.post requests for my app's backend, I noticed a security issue. When inspecting the data using tools like firebug in Firefox, I can see all the information being sent. Is it possible for third parties to intercept this data? Th ...

When combining AJAX with PHP and HTML, one limitation to note is that PHP alone cannot generate or create the file

I am facing a particular problem here. Currently, I am using HTML with AJAX: <html> <head> <script> function ajax_post(){ // Create our XMLHttpRequest object var hr = new XMLHttpRequest(); // Create some variables we need to ...

The issue of Ajax response not triggering the ng-click function

When attempting to pass data through an AJAX return, I encountered an issue with a function that writes an ng-click in Angular 1. The code snippet is as follows: $.ajax({ 'method': 'GET', 'url': base_url +&apos ...

Python encounters issues when attempting to parse and interact with a JSON file

In my current role, I've been tasked with creating a Python function to validate data within a JSON file. The catch is, the only way to access this JSON file is by downloading it from a website. As the sole individual with coding experience (HTML, CSS ...

A nifty little JavaScript tool

Recently, I created a bookmarklet that opens a new window with a specified URL and passes variables to a PHP script using the GET method. However, I now require it to load the same PHP script and pass the same variables but within a div element this time. ...

Error: Conversion of "2018-01-01-12:12:12:123456" to a date is not possible for the 'DatePipe' filter

<td>{{suite.testSuiteAttributes && suite.testSuiteAttributes.modifiedTimestamp | date: 'yyyy-MM-dd' }} </td> I am trying to display the date in the "05-Feb-2018 11:00:00 PM CST" CST format, but I keep getting an ...

Tips for making an appended element match the height of an image

After embedding the div .soonOverlay into specific .smallCatalogBlock's, I am facing difficulty in adjusting the height of soonOverlay to match only the height of the img within smallCatalogBlock. Currently, its height extends throughout the entire co ...

Instructions for saving a binary file on the client using jQuery's .post function

I am working with a handler that has the following code: HttpRequest request = context.Request; HttpResponse response = context.Response; if (request["Type"] != null) { try { string resultFile = null; ...

Steps for setting up i18nextStart by including the i

I am working on developing a multilingual app using the i18next package. Unfortunately, I am experiencing issues with the functionality of the package. Below is an example of the i18next file I have been using: import i18n from "i18next"; impor ...

Is it possible to generate a Token in Nexus for private packages without using the UI interface?

We have implemented Sonatype Nexus Repository ManagerOSS 3.29.0-02 and are currently facing an issue in generating a TOKEN that can be used with .npmrc following this specific structure: registry=http://NEXUS-IP:8081/repository/GROUP-NAME http://NEXUS-IP:8 ...

Serve up a 400 error response via the express server when hitting a

I need help serving a 400 error for specific files within the /assets directory that contain .map in their names. For example: /assets/foo-huh4hv45gvfcdfg.map.js. Here's the code I tried, but it didn't work as expected: app.get('/assets&bs ...

Error encountered in Json deserializer: 'Unexpected character found during value parsing: S. Path', on line 0, at position 0

Trying to implement CRUD functionality for the Recipe table has been successful in the API aspect, but encountering a roadblock in the MVC Update part. Upon accessing the update view, the fields should already be populated, unlike when creating a recipe fr ...

Tips for retrieving the identifier of a row in a mui datagrid when an onClick event occurs

I'm attempting to integrate a material-ui datagrid with a sql database for the purpose of enabling edits to be made via a form rather than editing individual rows and cells one by one. My goal is to pass the row's id as a parameter to a function ...

How can we redirect to another page after checking a box?

In the scenario where a checkbox is checked, how can the page be automatically redirected to @habit, simulating the behavior of clicking a submit button? habits/show <% if @habit.current_level_strike %> <div class="btn" id="red"> <l ...

Tips for transferring the name field to a different page upon clicking

There are two pages in my project - the first one is called ItemMenuPage and the second one is called CartPage. The functionality I am trying to achieve is that when a user clicks on any item name on the ItemMenuPage, it should navigate to the CartPage, wi ...

What is the most effective way to assign multiple functions to the onClick event of a button, based on a specific property,

I have a special button that generates a specific type of code when rendered: <button>{this.props.text}</button> This button is named ButtonCustom. In the render method of the main container, I am trying to achieve the following: function my ...