MySQL Query not giving expected result - mysql

In my XAMPP server's database, table named report exist which consist several column with there fixed set of values (Ok, Not Ok, Done, Not Done, Not Available). For some column like, column 'battery' , when I fire query in XAMPP sql as "SELECT * FROM Report WHERE battery='yes'"; it returns 0 set of result(no records) even when there are several records in which battery value is 'yes'. It's also not working for selecting value 'no';
I think my query is correct but the output is wrong. Please help with solution for this. Also I am not making any spelling mistake related to database, table and column name.
SELECT * FROM report WHERE battery='yes';
SELECT * FROM report WHERE battery='no';
output : MySQL returned an empty result set (i.e. zero rows). (Query took 0.0044 seconds.)

Related

Update query does not return any values

When I try to create a simple update query with Subtraction or anything else in the same table, it doesn't return me any value, could it be something to do with formating?
This is SQL code: UPDATE Sales SET Sales.GrossProfit = [SubTot]-[Cost];
It doesn't return any value.
I have copied syntax from different databases (from colleagues) where the same type of query worked. Could it be something to do with my general Access settings?
UPDATE Sales SET Sales.GrossProfit = [SubTot]-[Cost];
I expect the query to update the GrossProfit column with the calculation "SubTot - Cost"
Strictly speaking, an UPDATE query does not "return" any columns. It only changes data in existing rows, but by itself does not return those changes back to you. (It is more accurately called an Update statement since it does not return data.)
For instance, if you were to execute the UPDATE statement in VBA code, you would not get a RecordSet of columns like with a SELECT query. To get the results after executing the UPDATE statement would require that you execute a separate SELECT query.
However, I assume that you are viewing the Update query in the Access query designer. Correct?
In that case, when you click on the View button (Datasheet View), Access tries to be smart & useful about the UPDATE and converts it temporarily into a SELECT query so that you can visualize the existing data in the columns. The Datasheet View does not actually run the UPDATE statement, nor does it show a preview of what will happen when you do run it.
While in Design View or SQL View for an Update query (or for Delete, Make Table, and Append queries), there is a Run button with a red exclamation point (on the Design ribbon/toolbar). Clicking that button will actually execute the query that changes the table values. Although it will not show you results row by row, you should get a pop-up telling you how many rows were changed due to the statement. (You may also get confirmation prompts that the statement is about to change data in the table.)

the sql statement used to create a table?

what is the query that outputs the sql statement used to create a table?
You should check it in the output window of the mySQL workbench. It shows the query you executed along with many other useful information like the success or failure result of the query execution, time taken, affected row count etc. I've marked the last query I executed in red box.

phpMyAdmin: Create column that increments after updating any data in its row

I have an SQL database with over 800 entries and 40 values for each entry. I would like to add a column that increases every time any of that row's values change. It would be like a version number for each individual row so I know which rows have edited data.
I know little to nothing about sql coding, I just use phpmyadmin to hold my data. Is something like this possible without adding some sort of function, and if not, how would I go about implementing something like this. Any input would be appreciated.
You can use triggers to do this job. Run the following query in phpmyadmin after editing the table name and column name for count
CREATE TRIGGER incr_on_update BEFORE UPDATE ON yourtablename
FOR EACH ROW SET NEW.count =OLD.count+1;

Unable to do an INSERT INTO using a SELECT where the SELECT is `information_schema`.`COLUMNS`

This one really stumps me. I'm trying to create a MySQL query that I can populate information into a columns table to then export into SQLite. I can populate just about anything I want, except when the SELECT statement comes from information_schema.COLUMNS.
Here's a simple example to test. I created a table called TestTbl in a schema called and gave it 2 rows. The first is an AUTO INCREMENT INT id row, and the 2nd is a varchar 100 row called Namedb. I then run the following query.
INSERT INTO `tblinfoetc`.`testtbl` (Namedb)
SELECT
`COLUMNS`.`TABLE_SCHEMA` AS `Namedb`
FROM
`information_schema`.`COLUMNS`;
My message after doing this is:
Affected rows: 0
Time: 0.000s
If I run this without the INSERT INTO line, it returns the records without a hitch. Any ideas?
This is more of a workaround suggestion than a real solution:
Selecting from information_schema.columns works fine, so try doing the operation in two steps. First, copy the data using a client interface then insert it into the destination table from the client.
I have encountered the same problem on a windows machine running mysql 5.6.13. The query used to work with mysql 5.5. It might be related to this other issue

SHOW TABLES and MYSQL_NUM_ROWS

I have just noticed that where mysql_num_rows should return the number of rows returned for either SELECT or SHOW commands, returns 0 for SHOW TABLE command specifically.
Instead it shows the affected rows count instead of the num rows.
Can anyone please tell me if this is a bug or if am I missing anything here?
SHOW TABLE command is used to Show you table name in your database . On the other hand , mysql_num_rows is used to count how many result got from your query. This query is depend on your requirement basis ...
As stated on the PHP documentation page:
Retrieves the number of rows from a result set. This command is only
valid for statements like SELECT or SHOW that return an actual result
set.
My guess is that SHOW TABLES is not a technical query that would produce the type of result set that mysql_num_rows enumerates.
These "helper" functions (such as SHOW, EXPLAIN, DESCRIBE etc.) won't let you issue their results like you would in a regular table.
But if you're looking for how you can do this, for SHOW TABLES you can do
SELECT `table_name` FROM `information_schema`.`tables`
WHERE `table_schema`=DATABASE()
-- DATABASE() selects current database name
-- you can use the name of any database as a string instead
So basically you can use the information_schema database to get that information.
It was a bug in mysql, fixed it with the update.