ilan Expert Licensed User Longtime User Dec 27, 2023 #1 hi for my app i need to perform a query but i am not sure how to do it. i need to retrieve the record by a column but i allow the user to arrange it. so i have a table where the user can get all categories (table2) and he is allowed to arrange the order how he like and i store it under catpos (column name) then i have a table with items (table1) and i need to get all records in order of the other table catpos ASC something like this: i guess i need to use JOIN somehow right? Last edited: Dec 27, 2023
hi for my app i need to perform a query but i am not sure how to do it. i need to retrieve the record by a column but i allow the user to arrange it. so i have a table where the user can get all categories (table2) and he is allowed to arrange the order how he like and i store it under catpos (column name) then i have a table with items (table1) and i need to get all records in order of the other table catpos ASC something like this: i guess i need to use JOIN somehow right?
ilan Expert Licensed User Longtime User Dec 27, 2023 #2 ok got it B4X: Copy SELECT t1.* FROM "table1" AS t1 JOIN "table2" AS t2 on t2.category= t1.category ORDER BY t2.catpos sql is really fun Last edited: Dec 27, 2023 Upvote 0
ok got it B4X: Copy SELECT t1.* FROM "table1" AS t1 JOIN "table2" AS t2 on t2.category= t1.category ORDER BY t2.catpos sql is really fun
yiankos1 Well-Known Member Licensed User Longtime User Dec 27, 2023 #3 For complex sql queries joining tables etc i ask chatgpt after posting tables structure. It gives quite good answers Upvote 0
For complex sql queries joining tables etc i ask chatgpt after posting tables structure. It gives quite good answers
LucaMs Expert Licensed User Longtime User Dec 27, 2023 #4 ilan said: sql is really fun Click to expand... It's powerful but I wouldn't call it fun ? Upvote 0
LucaMs Expert Licensed User Longtime User Dec 27, 2023 #5 yiankos1 said: For complex sql queries joining tables etc i ask chatgpt after posting tables structure. It gives quite good answers Click to expand... It's true, if you can describe well what you want to achieve ChatGPT is very useful for this type of need. Upvote 0
yiankos1 said: For complex sql queries joining tables etc i ask chatgpt after posting tables structure. It gives quite good answers Click to expand... It's true, if you can describe well what you want to achieve ChatGPT is very useful for this type of need.
ilan Expert Licensed User Longtime User Dec 27, 2023 #6 yiankos1 said: For complex sql queries joining tables etc i ask chatgpt after posting tables structure. It gives quite good answers Click to expand... i tried what you say i asked: write me a query to get a record from one table order bey a column and another table and this is what chatgpt answered: B4X: Copy SELECT t1.* FROM table1 AS t1 JOIN table2 AS t2 ON t1.common_column = t2.common_column ORDER BY t2.another_column_to_order_by; ? not bad at all. chatgpt gave me the correct answer. very useful Upvote 0
yiankos1 said: For complex sql queries joining tables etc i ask chatgpt after posting tables structure. It gives quite good answers Click to expand... i tried what you say i asked: write me a query to get a record from one table order bey a column and another table and this is what chatgpt answered: B4X: Copy SELECT t1.* FROM table1 AS t1 JOIN table2 AS t2 ON t1.common_column = t2.common_column ORDER BY t2.another_column_to_order_by; ? not bad at all. chatgpt gave me the correct answer. very useful
E emexes Expert Licensed User Longtime User Dec 27, 2023 #7 ilan said: B4X: Copy ORDER BY t1.column_to_order_by, t2.another_column_to_order_by; Click to expand... Lol you almost beat me to what I was in middle of writing, which was to consider adding t1.name as a secondary sort column eg: SQL: Copy SELECT t1.* FROM "table1" AS t1 JOIN "table2" AS t2 on t2.category= t1.category ORDER BY t2.catpos, t1.name Upvote 0
ilan said: B4X: Copy ORDER BY t1.column_to_order_by, t2.another_column_to_order_by; Click to expand... Lol you almost beat me to what I was in middle of writing, which was to consider adding t1.name as a secondary sort column eg: SQL: Copy SELECT t1.* FROM "table1" AS t1 JOIN "table2" AS t2 on t2.category= t1.category ORDER BY t2.catpos, t1.name
M Mahares Expert Licensed User Longtime User Dec 27, 2023 #8 ilan said: sql is really fun Click to expand... Since you are having fun with SQLite here is another way of writing the syntax. You do not need the word 'AS' and you can replace the JOIN with a comma, and you do not need the double quote around the table name: Code: Copy SELECT t1.* FROM table1 t1 , table2 t2 ON t1.category=t2.category ORDER BY t2.catpos Upvote 0
ilan said: sql is really fun Click to expand... Since you are having fun with SQLite here is another way of writing the syntax. You do not need the word 'AS' and you can replace the JOIN with a comma, and you do not need the double quote around the table name: Code: Copy SELECT t1.* FROM table1 t1 , table2 t2 ON t1.category=t2.category ORDER BY t2.catpos