Need your help guys in forming a query. Example. Company – Car Rental Table – Cars Now, how do I select only one entry from this table which satisfies the below conditions? If Mercedes is available in Showroom, then fetch only that row. (i.e. row 1 in above example) But If none of the Mercedes are…
Tag: sql
How to store a list in a column of a database table
So, per Mehrdad’s answer to a related question, I get it that a “proper” database table column doesn’t store a list. Rather, you should create another table that effectively holds the elements of said list and then link to it directly or through a junction table. However, the type of l…
What is an unbounded query?
Is an unbounded query a query without a WHERE param = value statement? Apologies for the simplicity of this one. Answer An unbounded query is one where the search criteria is not particularly specific, and is thus likely to return a very large result set. A query without a WHERE clause would certainly fall in…
Oracle join query
There are three tables in my db: ITEM_MASTER, PRICE_MASTER and COMP_MASTER. ITEM_MASTER STORE_CODE ITEM_CODE ITEM_DESC 011 914004 desccc PRICE_MASTER STORE_CODE ITEM_CODE COMP_CODE …
Indexes and multi column primary keys
In a MySQL database I have a table with the following primary key In my application I will also frequently be selecting on item by itself and less frequently on only invoice. I’m assuming I would benefit from indexes on these columns. MySQL does not complain when I define the following: But I don’…
Keep history in django to draw graphs
I am looking for the best way to have an history of my models (interger & float fields) in Django. I read Keeping a history of data changes in database and it seems that triggers are the best …
TSQL – make a literal float value
I understand the host of issues in comparing floats, and lament their use in this case – but I’m not the table author and have only a small hurdle to climb… Someone has decided to use floats as you’…
Is there a combination of “LIKE” and “IN” in SQL?
In SQL I (sadly) often have to use “LIKE” conditions due to databases that violate nearly every rule of normalization. I can’t change that right now. But that’s irrelevant to the question. Further, I often use conditions like WHERE something in (1,1,2,3,5,8,13,21) for better readabilit…
Group by date range on weeks/months interval
I’m using MySQL and I have the following table: I want to be able to generate reports like this, where periods are done in the last 4 weeks: or in the last 3 months: Any ideas how to make select queries that can generate the equivalent date range and clicks count? Answer
CakePHP adding columns to a table
I have a Profile model/controller in my cake app as well as an index.ctp view in /views/profiles. Now, when I go to add a column to my table that is already filled with data, and then add the …