PROBLEM WITH SQLITE - View with several selects

Asked

Viewed 236 times

1

I have three tables that I have to take a dice in each to make an algorithm in the app, only I would like to know if there is a view that brings me this three data that are in the different tables. I’d like to know if there’s any way I can do this because none of the tables are related, so with a JOIN is not possible.

But if a select does not return anything "0 Row(s) affected" it does not bring any of the other tables, it would be possible to put a value default? so that the result of the others brings even if one of them brings no value

The select’s to be made are those:

SELECT PrecoBase FROM tbPRECOBASE WHERE Warehouse_Origem = "1" AND Numero_Item = "g";
SELECT * FROM tbPDISC WHERE Division = "BOV" AND Customer = "0" AND Customer_Type = "VD" AND Item_Number = "s" AND date('now') BETWEEN Date_Start AND Date_Finish;
SELECT * FROM tbPDISCQT WHERE tbPDISCQT.Numero_Item = "D53510B" AND 71>=CAST(tbPDISCQT.Quantidade_Inicial AS INTEGER) AND Tipo_Cliente = "JOS" AND DATE('NOW') BETWEEN Data_InicialData_Final; 

Note: by the rule always the table tbPRECOBASE will bring some result, the others not always.

  • Put the layout of the tables !!! I believe help answer your question, better, edit your question by placing the table layout and right after which fields you want to bring !!!

  • I will put here the selects, so that by the rule always the table tbPRECOBASE will bring a response the others will bring and sometimes will not bring SELECT Precobase FROM tbPRECOBASE WHERE Warehouse_origin = "1" AND Numero_item = "g";
SELECT * FROM tbPDISC WHERE Division = "BOV" AND Customer = "0"
AND Customer_Type = "VD" AND Item_Number = "s" AND date('now') BETWEEN Date_Start AND Date_Finish;



SELECT * FROM tbPDISCQT WHERE tbPDISCQT.Numero_Item = "D53510B" AND 71>=CAST(tbPDISCQT.Quantitystarting AS INTEGER) AND Tipo_client = "JOS" AND DATE('NOW') BETWEEN Data_initial_ata_final;

1 answer

2

You can create views yes, follow the official documentation link Sqlite.

And here a similar issue in the SOEN.

Example:

/* criar a view */
CREATE VIEW VIEW1 AS
SELECT T1.*, T2.*, T3.* FROM TABELA1 AS T1, TABELA2 AS T2, TABELA3 AS T3

/* executar a view */
SELECT V1.* FROM VIEW1 AS V1

It is not necessary to have any link between the tables, to use them, in the VIEW, although it doesn’t seem to have much logic.

  • 1

    I think his question is how to view tables that don’t relate...

  • 2

    @NULL, Just take the select that he already uses today and put in the view, I believe he already do this select today.

  • +1! Thank you for editing.

  • but if a select does not return anything "0 Row(s) affected" it does not bring any of the other tables, would it be possible to put a default value? so that the result of the others brings even if one of them does not bring any value

  • @user7791, there is already a problem, and in case it is not even a matter of being VIEW, the SELECT has this behavior, I do not know how to get around it, I hope some colleague can help us. Stay behind to edit.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.