I need to check if a database is totally empty (no tables) using an SQL query. How can this be done? Thanks for the help! Answer will return the actual number of tables (or views) in your DB. If that number is 0, then there are no tables.
Tag: mysql
How do I subtract using SQL in MYSQL between two date time values and retrieve the result in minutes or second?
I want to subtract between two date time values using SQL in MySQL such that I get the interval in minutes or seconds. Any ideas? I want to run a SQL query that retrieves uses from a database who have logged in like 10 minutes from the time. Answer There are functions TIMEDIFF(expr1,expr2), which returns the value of expr1-expr2, and
MySQL INTO OUTFILE override existing file?
I’ve written a big sql script that creates a CSV file. I want to call a cronjob every night to create a fresh CSV file and have it available on the website. Say for example I’m store my file in ‘/…
Using column alias in WHERE clause of MySQL query produces an error
The query I’m running is as follows, however I’m getting this error: #1054 – Unknown column ‘guaranteed_postcode’ in ‘IN/ALL/ANY subquery’ My question is: why am I unable to use a fake column in the where clause of the same DB query? Answer You can only use column aliases in GROUP BY, ORDER BY, or HAVING clauses. Standard SQL doesn’t allow
What is the equivalent of ‘go’ in MySQL?
In TSQL I can state: In MySQL I can’t write the same query. What is the correct way to write this query in MySQL? Answer Semicolon at the end of the statement.
How do I UPDATE a row in a table or INSERT it if it doesn’t exist?
I have the following table of counters: I would like to increment one of the counters, or set it to zero if the corresponding row doesn’t exist yet. Is there a way to do this without concurrency issues in standard SQL? The operation is sometimes part of a transaction, sometimes separate. The SQL must run unmodified on SQLite, PostgreSQL and
MySQL query to extract first word from a field
I would like to run a query that returns the first word only from a particular field, this field has multiple words separated by spaces, I assume I may need to carry out some regex work to accomplish this? I know how to do this using a few ways in PHP but this would best be carried out on the
How can I SELECT rows with MAX(Column value), PARTITION by another column in MYSQL?
I have a table of player performance: What query will return the rows for each distinct home holding its maximum value of datetime? In other words, how can I filter by the maximum datetime (grouped by home) and still include other non-grouped, non-aggregate columns (such as player) in the result? For this sample data: the result should be: id home
How do I list the first value from a three-way joined table query?
Ugh ok I’m terrible at explaining things, so I’ll just give you the quotes and links first: Problem 4b (near bottom): 4b. List the film title and the leading actor for all of ‘Julie Andrews’ films….
How to resolve ambiguous column names when retrieving results?
I have two tables in my database: NEWS table with columns: id – the news id user – the user id of the author) USERS table with columns: id – the user id I want to execute this SQL: SELECT * …