I have the following SQL: Since I have multiple environments, that PK_PS_userVariables constraint name is different on my different databases. How do I write a script that gets that name then adds it into my script? Answer While the typical best practice is to always explicitly name your constraints, you can …
Tag: sql
Exporting SQL table using phpMyAdmin gives no results for large data sets
When I open my table in phpMyAdmin and click Export (selecting .zip from the save-as options), I get an empty (0 byte) zip file. The table has ~200 000 records. This problem does not occur for smaller tables. This problem also does not occur when I export only the first 60 000 records. Is this a bandwidth lim…
Doing a WHERE .. IN subquery in Doctrine 2
I’d like to select order items from all orders with a specific item. In SQL I’d do it like this: How would I do this query with the query builder? Answer This is how I would try it: I didn’t test this of course, and made some assumptions about your models. Possible problems: Limit: this has …
How to add minutes to datetime?
I want to add minutes that already exist in same table. I have a datetime and a duration. I want to get the start date/time as well as the end date/time. I can use datetime but have to specify ‘localtime’ which doesn’t work. I want the equivalent of DATEADD in SQL Server. Answer Try start_da…
Completely copying a postgres table with SQL
DISCLAIMER: This question is similar to the stack overflow question here, but none of those answers work for my problem, as I will explain later. I’m trying to copy a large table (~40M rows, 100+ …
How to write condition wise result providing query?
I want to write a MySQL query that gives a condition wise result. For example. I have a table with question, answer value, user chose value fields. User can attend to answer that question many times. qid rightanz wronganz 11 4 2 11 4 4 11 4 1 25 1 1 I want out put like this qid rightanz wronganz
Direct method from SQL command text to DataSet
What is the most direct route to get a DataSet if I have a sql command? string sqlCommand = “SELECT * FROM TABLE”; string connectionString = “blahblah”; DataSet = GetDataSet(sqlCommand,…
Keep only N last records in SQLite database, sorted by date
I have an SQLite database that I need to do the following: Keep only last N records, sorted by date. How do you do that? Answer To delete all but the latest 10 records.
‘LIKE (‘%this%’ OR ‘%that%’) and something=else’ not working
I have a select query where I am trying to search strings for multiple patterns Returns zero results However returns results and returns result Is it possible to get all my results into one query? If a string matches both, how will it handle that? Answer It would be nice if you could, but you can’t use …
Format() function doesn’t work?
I am trying to execute following built-in function in sql but it gives me error that this function doesn’t exist my query: Error i am getting: What may be the problem, or what am i doing wrong? Thanks! Answer Use Convert function instead. Example: