Skip to content

Tag: mysql

How do I properly optimize this query?

I’m trying to optimize the following query. I’ve used EXPLAIN to troubleshoot but it keeps showing up in our logs as a non-indexed query. What am I missing? I’ve created indexes on all columns referenced, but it’s still showing up. Answer If you have a big table which contains millions…

MySQL to Microsoft SQL Server derived table syntax

I am trying to select data from a derived table created in the FROM statement. I have the following code in MySQL: I’m trying to do the same in Microsoft SQL Server, but this doesn’t work, with an error ‘incorrect syntax’. I’ve tried a few different combinations, and anything I c…

How do I sort a table with non alphabetical values?

I’m a non-programmer and want to use the power of SQL to sort my inventory data. Here’s the sample table that I have. I want to turn this data to this. How can I query my table to have a result like this below Answer These two suggestions – if stick to the datasets given. If you’re on …

Trying to do basic subtraction from a database table

I’m trying to subtract data based on user input, for example: UPDATE table SET quantity=quantity – * some input value* This is easy if I’m subtracting field by field, where id=1…2…3, but I want to subtract values automatically when I input quantity, so if input is 60, and there i…