How to return rows where a column has 2 words (that is, strings separated by a space) in it? It must be purely using SQL. Answer I dont know the names when querying. Its a big dataset. I only have to check if the name contains a spacebar basically (from a comment). If you want to distinguish names that have
Tag: sql
how to get current/Todays date data in sql server
how to write query to get today’s date data in SQL server ? select * from tbl_name where date =
SQL – Convert String to Date and compare – Conversion failed when converting datetime from character string
I currently have dates stored in a general attribute field in the database as a string. They are all stored in the format DD/MM/YYYY for example 01/01/2000 I am able to convert them them to datetime …
Using Inner join and sorting records in descending order
I am working with two tables(student_class and class) in my database. I have a query below that shows class that have students. But it is not quite what I am looking for. How to display classes that have students but show the results so maximum seats is descending. Would count be needed? Tables: Student_class…
PostgreSQL distinct rows joined with a count of distinct values in one column
I’m using PostgreSQL 9.4, and I have a table with 13 million rows and with data roughly as follows: There are indices on md5(a), on b, and on (md5(a), b). (In reality, a may contain values longer than 4k chars.) There is also a primary key column of type SERIAL which I have omitted above. I’m tryi…
SQL not recognizing column alias in where clause
I am only a beginner in SQL, but I’ve come across this annoying error. SQL is having an issue with the WHERE clause of this script: SELECT ITEM_ID, ITEM_PRICE, DISCOUNT_AMOUNT, QUANTITY, (…
JPA @Column annotation to create comment/description
I was wondering is it possible to create from jpa/hibernate annotation a database column description/comment like this: ALTER TABLE tablename CHANGE status status INT(11) NOT NULL COMMENT ‘sample description/comment’; It will be great functionality, but I cant find anything about this in JPA speci…
How to count the number of rows with a date from a certain year in CodeIgniter?
I have the following query. $query = $this->db->query(‘SELECT COUNT(*) FROM iplog.persons WHERE begin_date LIKE ‘2014%”); I need to count the number of columns with a begin_date in the year …
SET CONSTRAINTS ALL DEFERRED not working as expected
In a PostgreSQL 9.3 database, if I define tables a and b as follows: And then do the following: It produces the error below. Why is SET CONSTRAINTS not having the desired effect? Answer Only DEFERRABLE constraints can be deferred. Let me suggest superior alternatives first: 1. INSERT in order Reverse the sequ…
Rails Query with ILIKE
I have written a finder as follows: params[:manufacturer] comes through in a form of a string that has been .parameterized by Rails. The problem is that a string with an “‘” or an “&” in it doesn’t get matched by ILIKE correctly. So as an example, some strings that are …