AlaSQL / alasql

AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.
http://alasql.org
MIT License
7.04k stars 659 forks source link

Subquerys dont work as expected #853

Open peon501 opened 7 years ago

peon501 commented 7 years ago

I see statements like this dont work

SELECT (SELECT Name from SomeKindOfTable as sm WHERE sm.Id=m.Id) FROM Main as m

Is it bug or not supported ?

peon501 commented 7 years ago

ps I use indexeddb database.

mathiasrw commented 7 years ago

Hmm. Does this work in other databases? Looks like you are doing a join without doing a join.

I would be really awesome if you could provide an example with the data in sm and m together with the expected output...

Have you tested with its not indexeddb?

peon501 commented 7 years ago

SELECT HardServiceId, h.ClientId, h.Name, h.Date AS RegDate, h.Duration AS EndTime, h.VisitDate AS PlanDate, h.Address, h.City, (SELECT op.Name FROM Options_Details as op WHERE op.OptionDetailId = h.ServiceId) AS Type,

(SELECT op.Name FROM Options_Details as op WHERE op.OptionDetailId = h.StatusId) AS Status FROM HardService as h

before I used sql.js https://github.com/kripken/sql.js/

now Iam doing

JOIN Options_Details as opse ON opse.OptionDetailId=h.ServiceId JOIN Options_Details as opst ON opst.OptionDetailId=h.StatusId

because subselects dont work

javascript code: alasql('ATTACH INDEXEDDB DATABASE database;USE database;', [],function(){ // Select data from IndexedDB alasql.promise(sql_statement)) .then(callback); }); sql_statement is SQL select above

peon501 commented 7 years ago

Joins are slow if you only need 1 column. I dont want to join whole table to other table. Normly all sql engines allows you to do that like i showed.

peon501 commented 7 years ago

I could be wrong about speeds :) in internal. but anyway subselect should work 😄 .