I have a table passenger_count pas1_id pas2_id count 1 6 2 14 37 4 that connects by pas_id with another table passenger: id name 1 Bruce k 2 George L 3 Li Wo 4 Don Wa How to replace pas1_id, pas2_id with actual names from passenger table? This self join query does not work: Answer Just join passenger to passe…
Inserting an ID that increments (but is not an AUTOINCREMENT)
I have a table that I am trying to insert multiple records into using a select statement. The ID field is an INT and not autoincremented but I do need to increment in in the INSERT. The table belongs to a third party product we use for our ERP so I cannot change the property of the ID. The insert
Out of Range Error while inserting into a MySQL decimal column
I have this tabular structure: I get an error when i try to insert a specific set of value, query with those values is as below: For longitude with value -161.9722021 it is throwing me an error, values less than 100 value were successfully inserted. I don’t see the value being out of range, the value i …
Django – complicated ORM Query (related_set)
I have model Car, Listing and Website. I want to filter all car objects that have listing object on the given website but the listing needs to be active. To get all car objects that have listing object on the given website: But how do I filter out inactive listings? I want something like: Answer You would do …
Where clause on custom column
select c.base_id,case when c.type is not null then c.type else g.type end as type, c.function_id from cust c left join category cg on c.cat_id=cg.id where c.type=’privelleged’; — where clause is …
How is NOT(IS NULL) different from IS NOT NULL in SQL?
What’s wrong with this SQL query? SELECT * FROM database.tablename WHERE columnname NOT (IS NULL) since IS NULL is a Boolean value, why doesn’t NOT negate it? rather it returns this Error Code: …
About “group function is not allowed here”
I have a table with job, salary and date columns. I am writing the following query in PL/SQL, but I am getting an error group function is not allowed here How can I solve this problem? Answer Your query makes no sense (to me, at least). What does that average salary represent? Whose average salary? Here’…
Left join on 1:M relation by maximum value in non joinable column
I am solving this kind of problem on PostgreSQL database using SQL. I have 2 tables, for simplicity assume they have only these columns and have 1:M relation. Table A: Name Type Note id long primary …
presto sql filter part of the string java
I have a string in col1 select col1 from table “blah blah 123 blah iterate 866 loss blah blah” how to filter string between iterate and loss and just show sum of all such filtered numbers ? Answer You can use regexp_extract to extract the number within that string, convert the values to a numeric …
How to select optimal batch size in JDBC?
I have a CSV file with 50000 entries which I want to import in SQL using batch in JDBC. What should be the optimal batch size for it?