Here is my table layout: What I would like to do: Count the number of votes for each songID in a particular room (passed in as a parameter). Find out if the userID has at least one vote for a song in a particular room. UserID is also passed in as a parameter. An extension of the two above. If
Tag: sql
Query to check if date is between two month-day values
I want to know if a date (Year-Month-Day) is between a day of the month (Month-Day). For example, I want to know if ‘April 2, 2013’ is between ‘April 2’ and ‘April 19’. I can easily do this of the range has a year value. Howver, without a year, I need ideas how to do this. …
ERROR 1148: The used command is not allowed with this MySQL version
I am trying to load data into mysql database using the topic of this question is the response I get. I understand the local data offloading is off by default and I have to enable it using a the command local-infile=1 but I do not know where to place this command. Answer You can specify that as an additional o…
How to visualize database tables in postgresql using pgAdmin?
I am trying to visualize tables and their relations using pgAdmin. I have understood that there is a query visualizer tool available for pgAdmin. However, that only is useful if you are dealing with queries. My main goal is to generate a graphical representation of all the tables available in database. Answer…
meta_query, how to search using both relation OR & AND?
Resolved: See answer below. I have a custom post type called BOOKS. It has several custom fields, named: TITLE, AUTHOR, GENRE, RATING. How do I fix my meta_query code below so that only books that have the search word in the custom fields: title, author, genre WITH EXACTLY the rating specified in my search fo…
How to get a count even if there are no results corresponding mysql?
I am formalating a query to give the number of reports submitted over the last year ordered by date. I get the current year and month with php: and execute the following query: SQL: And because there has only been 1 submitted in the last year it gives me only 1 result… But I would like the result set to
Sql Command Not Working
I wrote the following code, but nothing is being inserted into the database. I tried changing the SA password in the connection string to something incorrect and the code isn’t catching the exception. What am I doing wrong? Answer As stated by the OP in the comments. Once the try-catch was resolved it w…
How to avoid multiple function evals with the (func()).* syntax in a query?
Context When a function returns a TABLE or a SETOF composite-type, like this one: the results can be accessed by various methods: select * from func(3) will produce these output columns : select func(3) will produce only one output column of ROW type. select (func(3)).* will produce like #1: When the function…
PostgreSQL – dump each table into a different file
I need to extract SQL files from multiple tables of a PostgreSQL database. This is what I’ve come up with so far: However, as you see, all the tables that start with the prefix thr are being exported to a single unified file (db_dump.sql). I have almost 90 tables in total to extract SQL from, so it is a…
How to create/add a column in an SQL select query based on another column’s values?
I want to dynamically add another column hook_name, via an SQL select query, based on a condition. For example if hook_type = 0, table hook_name should have a value of OFFER, and similarly for hook_type = 1, hook_name should show “ACCEPT”. Below is a screenshot of the result: The select query is t…