I am trying to run a SQL query to get four random items. As the table product_filter has more than one touple in product i have to use DISTINCT in SELECT, so i get this error: for SELECT DISTINCT, …
Tag: sql
RIGHT OUTER JOIN in SQLAlchemy
I have two tables beard and moustache defined below: I have created a SQL Query in PostgreSQL which will combine these two tables and generate following result: Query: However I can not create SQLAlchemy representation of it. I tried several ways from implementing from_statement to outerjoin but none of them …
Rails order method; column named :order
I have a model Exercises and it has columns of :circuit and :order (among others). In a view, I am trying to order the Exercises first by :circuit and then by :order. When I use the following: @…
How to fill Dataset with multiple tables?
I’m trying to fill DataSet which contains 2 tables with one to many relationship. I’m using DataReader to achieve this : But I’ve got only one table filled up. How do I achieve my goal – fill both tables? I would like to use DataReader instead DataAdapter, if it possible. Answer If you…
Add WHERE clauses to SQL dynamically / programmatically
How can I add search condition to SQL Stored Procedure programmatically? In my application(C#) I’m using stored procedure (SQL Server 2008R2) ALTER PROCEDURE [dbo].[PROC001] @userID varchar(20), @…
Can I parameterize the table name in a prepared statement?
I’ve used the mysqli_stmt_bind_param function several times. However, if I separate variables that I’m trying to protect against SQL injection I run into errors. Here’s some code sample: Is it possible to somehow replace the .$new_table. concatenation with another question mark statement, ma…
PostgreSQL IF statement
How can I do such query in Postgres? IF (select count(*) from orders) > 0 THEN DELETE from orders ELSE INSERT INTO orders values (1,2,3);
How do I create a trigger to insert a value into an ID field that is Max([ID Field])+1 on insert
When I add a new record I want SQL Server to automatically add a fresh ID. There are already some records which have been migrated over (from Access) and until I finish preparing the server for other required functionality I will be manually migrating further records over (if this affects any possible answers…
SQL performance MAX()
Just got a small question. When trying to get a single max-Value of a table. Which one is better? or I’m using Microsoft SQL Server 2012 Answer There will be no difference as you can test yourself by inspecting the execution plans. If id is the clustered index, you should see an ordered clustered index …
sql update multiple rows with subselect
I am trying to copy the corresponding graduation_date values from the graduation_term table into the rows in the user_education_mba_school table that have the matching graduation_term_id. Here is my …