I have the following table (simplification of the real problem): Now a simple SELECT id FROM Table WHERE value=’T’; would get me all the IDs where value is T, but I just need, in the example above, the first 2 (1 and 2). What is the best way to do this? I’d prefer not to use a while loop. I
adding summary row to the end of the table
Hi I have a table with 4 columns. the table is as below sampleId totalAmount discount netAmount 1 120 40 80 2 200 50 150 3 …
PHP – I want the user to have no possibility to upvote more than one time
I am working on a small social network with PHP and MySQL I want the users to have the possibility to upvote a post, and I already did this but the problem is that I want the user to be able to upvote only one time. Here is my PHP code: This is the form of the upvote button :
Count occurrences of distinct values
I am trying to find a MySQL query that will display the number of occurrences of an ID value within a year. Table: Expected output: I’m trying with the something along the lines of following sql query, but it gives me nothing like the expected output. It’s the 3rd column im struggling with. How ca…
How to use WHILE LOOP to add value to list with condition, SQL Server 2008
I have a loop query with scenario below: orderqty = increase value 1 each loop runningstock = decrease value 1 each loop allocateqty = case when orderqty > 0 and runningstock > 0 then 1 else 0 loop till runningstock=0 or total allocation=stockqty Query: Result: the correct one should be like this: Answe…
SQL How to display all records in group by
I have a table structure like this: UserID | Firstname | LastName | DateTime ——————————————- 1 | John | Doe | 2015-04-27 2 | Karl | Watts | …
How to see if date is in current month SQL Server?
I have a Ticket_Date column that is in the format YYYY-MM-DD HH:MI:SS I want to check if the Ticket_date is in the current month. So far I have : Ticket_date >= ‘2015-04-01’ and Ticket_date
Bulk insert in SQL Server database from one table to another
I have 200k records in one table and I want to insert these records into another table. I read about the bulk insert but the query I found on msdn website is just not making any sense. This is the query What is f:orderslineitem.tbl and the whole this is just not making any sense. I have a table with four
How do I solve this (SQL) query? [closed]
This is probably one of the simplest queries ever, and I’m probably just making it harder than it has to be, but I need it done. So, there’s three tables: TABLE AGENT ( A_ID INTEGER PRIMARY KEY, …
Postgres not allowing localhost but works with 127.0.0.1
Postgres not accepting connection if I say -h localhost but it works if I say -h 127.0.0.1 My /var/lib/pgsql/data/pg_hba.conf If I add following line then Postgres service failed to start: Wwhat is wrong there? Update My /etc/hosts file: Answer In pg_hba.conf, the first match counts. The manual: The first rec…