I’m having trouble with the getFetchSize() function. I simply need to know if the SQL query has returned zero rows. I’ve tried this simple statement: if (rs.getFetchSize()==0) System.out….
SELECT id HAVING maximum count of id
Have a products table with item_id and color_id. I’m trying to get the color_id with the most non-null instances. This fails: with This Returns I am looking for color_id 3, which has the most instances. Is there a quick and easy way of getting what I want without 2 queries? Answer This will give you the…
Can’t see MySQL BIT field value when using SELECT
my_table contains the enabled field which is defined as: enabled BIT NOT NULL DEFAULT 0. This table has multiple rows with enabled = b’0′, and multiple rows with enabled = b’1′. However, both this: …
Using a WHERE ___ IN ___ statement
I’m trying to figure out how to properly use a WHERE _ IN _ statement Definition: I’m trying to do something like this: Alternatively, I’ve also tried this, which directly evaluates to the above The error I am getting is: This is giving me an error. When I do it this way, it works, but this …
SELECT query where 1 column equals 2 variables
The issue: I want to select the products which have the option_value_id of both 1 and 3. But, as you can see, it will also show the products which have only have 1 of the option_value_ids. I tried …
Using macros in SAS SQL
I am wondering of I can consolidate some code into one PROC SQL statement instead of several back-to-back SQL statements. I am using macro to calculate the age of a participant at date of consent for a study, similar to what is provided here and here. I tried to troubleshoot the functionality of macros, and I…
MySQL: Count the distinct rows per day
I have an interesting query I need to do. I have a table with an INT column containing ip address numbers (using INET_ATON), and a timestamp column. I want to be able to count the number of unique ip address columns there are per day. That is, how many distinct ip rows there are in each day. So, for example,
SQL / MySQL – how to get a unique week number (independent of the year)?
I’d like to get the number of a week from a DATE starting with Monday as the first day of the week. While WEEK() can partially accomplish this, I would like each week to be uniquely identified. I.e.,…
PostgreSQL: FOREIGN KEY/ON DELETE CASCADE
I have two tables like here: So the logic is simple, after user removes all book under category x, x gets removed from cats, i tried method above but doesn’t work, after i clean table book, table category still populated, what’s wrong? Answer A foreign key with a cascade delete means that if a rec…
Conversion failed when converting date and/or time from character string while inserting datetime
I was trying to create a table as follows, create table table1(date1 datetime,date2 datetime); First I tried inserting values as below, insert into table1 values(’21-02-2012 6:10:00 PM’,’01-01-2001 …