We have two tables: “riders” and “drivers”. Some riders are also drivers, so will show up on both tables. Each table looks like this: Table riders I have tried this code: Write a query that outputs all SF riders and add a column called ‘flag’ that prints ‘true’ if the rider is also a SF driver and ‘false’ if …
Tag: sql
Does Oracle always resolve CTE with clauses even if they are not used in the result set
If I have an Oracle SQL query like this: Will the DBMS actually do the work of resolving/running query2, or does Oracle know that query2 is not required by the final output, so the work of that CTE/with should be skipped? Oracle version is 12c Enterprise. Answer I was going going to say “it’s up t…
What is the syntax error in this simple SQL query for creating a table?
I am trying out IntelliJ’s DataGrip to do some SQL work on a MariaDB database. Somehow i cannot execute the query that was automatically created by DataGrip itself…. Can you help me find the error in it ? The error is I tried to validate the query with an online validator and it seems fine… …
How to retrieve all grand parents at once
I have two simple tables in SQLITE3 (family bonds): “persons” (id, fname, lname) “relationships” (parent/child) I would like to get each grand children along with all their grand parents (from 1 to 4 of them depending on the grand child) so that 1 row result = Thanks to Caius Jard, I&#…
Returning a value before committing transaction and (UPDLOCK, HOLDLOCK)
I need to check if a record exists – if yes: then returns its id, if not: creates a new record and returns its id. I am using WITH (UPDLOCK, HOLDLOCK) in SELECT to prevent from duplicates (it creates lock). I wonder if I should commit the transaction if a record exists in a database for realising the lo…
Write a query to display the total month wise sales amount received in the past 1 year
Table StructureWrite a query to display the total month wise sales amount received in the past 1 year . Display details like sales month, total sales amount. Give an alias_name as MONTH for retrieved sales month, TURN_OVER for sales amount. Sort the result by amount in descending order. (Hint: Use table Sales…
R : x comparison (1) is possible only for atomic and list types
I am using R. In a previous post (R: Loop Producing the Following Error: Argument 1 must have names), I learned how to make a function (“create_data”) for my code. Now, I am trying to modify this function. First, I create some data to be used for this example: Here is the modified version of the f…
Find two values of one Column based on value of another column per ID
I have a sqlite db with one table that called Loan. This table with sample data is here: Loan Table at sqlfiddle.com This table contains below Columns: Now, I need a query to show desired result, contain [empid],[Codepayid],[Lval-1],[Lval-2],[Sum(Lint)],[Lrmn-1],[Lrmn-2], With this Conditions: For example: Re…
MYSQL Trigger not adding count after inserting rows into another table
This is a continuation of this question: Insert data into a table with a foreign key SQL I need to create a trigger that updates a counter variable after I insert a row into a table. The counter variable keeps track of how many new rows are inserted into the ItemBook table. However, after running the script, …
Android/sqlite – ContentResolver query with user input
Currently, I’m using this method to query all photos user’s phone has: I wanted to allow the user to filter the query by file names, so I added selection & selectionArgs part. (getSelectionArgs() returns “” if there is no user input. It returns the input if there is.) This method h…