Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Land Mime
Jul 13, 2007
Love never blows up and gets killed
This seems...wrong somehow, but creating an index on `timestamp` will make your query return the correct result. At least on MySQL 5.

edit: I mean I get why it works, it just seems to me that an index shouldn't affect the result of a query.

Land Mime fucked around with this message at 06:01 on Dec 8, 2007

Adbot
ADBOT LOVES YOU

Land Mime
Jul 13, 2007
Love never blows up and gets killed

Victor posted:

code:
select  timestamp = max(timestamp),
        search
from    searches
where userid = 1
group by search
order by max(timestamp)
limit 2

This also returns the incorrect result (at least on mysql 5). I think you might just have to chalk this up to a mysql bug since sqlite and postgres seem to do this correctly. Create the index and, ideally, compare database versions somewhere and die if its not your current one.

Land Mime
Jul 13, 2007
Love never blows up and gets killed

fletcher posted:

Hmm, I tried this, but every time I do a SELECT FOUND_ROWS() it always comes back with 1, even though the query where I put SQL_CALC_FOUND_ROWS into returns > 1 rows

If your not already, try using the command line client instead of something like mysql query browser.

Land Mime
Jul 13, 2007
Love never blows up and gets killed

Bitruder posted:

I have a table called "types" and a table called "items". Each item row is linked to a type row via a type ID number. I want to select every row in "types" and add on a column that returns the number of items that use that type. How can I do this? I've been experimenting with subqueries and joins but I can't get anything working.

Thanks! (I'm using mySQL 4.1)

You're looking for the GROUP BY and COUNT keywords. Your query would probably look something like

code:
SELECT `types`.`id`, COUNT(`items`.`id`)
FROM `types`
LEFT JOIN `items` ON `types`.`id` = `items`.`type_id`
GROUP BY `type_id`;

Land Mime
Jul 13, 2007
Love never blows up and gets killed
I know nothing about DTS or SQL Server but most databases have some sort of 'VACUUM' command that will reclaim unused space.

Adbot
ADBOT LOVES YOU

Land Mime
Jul 13, 2007
Love never blows up and gets killed

Numbnuts posted:

code:
CREATE TABLE tb_rltnshp_type
(
	rltnshp_type_cd  CHAR(3)  NOT NULL ,
	rltnshp_type_desc  VARCHAR(20)  NOT NULL  ,
	PRIMARY KEY (rltnshp_type_cd),
        UNIQUE (rltnshp_type_cd)
) WITH (OIDS=FALSE)
;
Someone please tell me I'm on the right track.

You're on the right track, but saying PRIMARY KEY is the same as saying UNIQUE and NOT NULL. What version of postgres are you using? I think WITH (OIDS=FALSE) is the default for more recent versions.

code:
CREATE TABLE tb_rltnshp_type
(
	rltnshp_type_cd  CHAR(3)  PRIMARY KEY ,
	rltnshp_type_desc  VARCHAR(20)  NOT NULL
)
;

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply