How to limit returned results of a JOIN query in MySQL [duplicate]

So assuming we can exclude the user table, it could be rewritten as: select * from expense, transaction where expense_id = transaction_expense_id Now if you want to apply a limit, you could do it like this: select * from expense, transaction where expense_id = transaction_expense_id and expense_id in (select expense_id from expense limit 1) Would … Read more

What cannot be done in SQL Server 2008 Web Edition?

Have you seen this matrix as well? http://msdn.microsoft.com/en-us/library/cc645993.aspx From what I can tell Web excludes a lot of the more advanced features, especially those related to development and data mining, but nothing that would stop you from using it for a non-enterprise web site’s data source. It seems to be between the Express version and … Read more

Best way to add a new column with an initial (but not default) value?

To add the column with a default and then delete the default, you can name the default: ALTER TABLE tbl ADD col INTEGER NOT NULL CONSTRAINT tbl_temp_default DEFAULT 1 ALTER TABLE tbl drop constraint tbl_temp_default This filled in the value 1, but leaves the table without a default. Using SQL Server 2008, I ran this … Read more

Composite key as foreign key (sql)

Per the mySQL documentation you should be able to set up a foreign key mapping to composites, which will require you to create the multiple columns. Add the columns and put this in your group table FOREIGN KEY (`beggingTime`,`day`,`tutorId`) REFERENCES tutorial(`beggingTime`,`day`,`tutorId`) As Steven has alluded to in the below comments, you SHOULD try to re-architect … Read more

PostgreSQL 9.1: How to concatenate rows in array without duplicates, JOIN another table

Instead of using window functions and partitioning, use a query-level GROUP BY and aggregate with a DISTINCT clause: SELECT rnp.grp_id, array_to_string(array_agg(distinct rnp.cabinets),’,’) AS cabinets, array_to_string(array_agg(distinct ips.address),’,’) AS addresses FROM rnp JOIN ips ON rnp.grp_id=ips.grp_id GROUP BY rnp.grp_id, ips.grp_id; Result: grp_id | cabinets | addresses ——–+————————-+———– 11 | cabs1,cabs2,cabs3,cabs4 | CA,NY 22 | c1,c2 | DC,LA … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)