Im using this: But my query is empty. I have also tried this (This one works): But obviusly my query only contains the max_id key. What am I doing wrong with the first one? Answer You need to add another level of select for the MAX, like this: A better approach would be to order by id in descending order,
Tag: select
MySQL query to get “intersection” of numerous queries with limits
Assume I have a single mySQL table (users) with the following fields: I want to be able to return the number of total records based on the number a user enters. Furthermore, they will also be providing additional criteria. In the simplest example, they may ask for 1,000 records, where 600 records should have gender = ‘Male’ and 400 records
SQL select when one condition or another are met but not both
Given the following table: what is the nicest way to query selecting rows when number 4 and 14 are selected in column1 or column2 BUT exclude when number 4 and number 14 are both in the row. Be aware that the order can be reversed. expected output Answer
Getting distinct values with the highest value in a specific column
How can I get the highlighted rows from the table below in SQL? (Distinct rows based on User name with the highest Version are highlighted) In case you need plain text table: What I have so far is (works for one user) Answer this might help you : sql fiddle
How can I return 3 COUNT columns from the same table when JOIN with other tables as well?
I would like to know how I can return several COUNTs for the following: I have 27 work sites, each site has an employee with a contract, I have wrote a script to return one actual column of data (…
Select a specific index row in sqlite
I have an index and I need to find out what is the row in a table with that index, in SQLite. Example: Index = 1 Table: Which is the correct SELECT that I can use to solve my problem? Answer Typically to get a specific row you can always request them by rowid, e.g. However, there are some atypical
SQL Server: round decimal number and convert to int (within Select)
I am using the following line within a Select which returns a number with decimals, e.g. 33.33333. How can I round this within the Select and convert to integers so that I don’t have decimals, e.g. in the above example it should return 33 ? Answer You can use ROUND function to round the value to integer: This will retain
Select info from a table referencing info from another table
I have a main product table with different products. Different products have different specs, so I’ve created separate specs tables for each product (there will be more than ten of them). What I want to do is to show individual product’s specs on a product_page.php whenever the product is clicked. My product page has columns: My specs table columns So
Avoid duplicates rows which have one different column value in SQL Server
I have a view like this . I’m using SQL Server. formId name mark 100 Rob N 101 Rob N 101 Rob C 105 Jane N 106 Jane N view name: …
Select by -3 days?
I’m trying to select data from a specific table in my database, but I want to be able to only view the last 3 days worth of data, I have the following code but for some reason I can’t get it to work. Answer You may avoid usage of DATE_ADD() at all: As @OGHaza mentioned, you specified column with alias