Skip to content
Advertisement

Return only one row in subquery

I have the following query that I’m executing to show these records on a Laravel view. I’m having issues with this line Because there are a lot of cities with the same name in my database, so it’s throwing an error, (probably the same with states but the error is being thrown at cities in this case, I tried to

Find all users with a unique last name

I have a table users. I wrote a sql query that displays all users with a unique last name tell my why query removes collapsed users name2 and name3? HAVING COUNT(DISTINCT u.first_name) = 1; How it works? help to understand how it works Answer The query is aggregating by last name and counting the number of users. Run this version

Update column value based on the multiple rows

I have a table example: (Col3 is bit datatype) I want to select distinct from the table except for col3 and update col3 value to 0 if col3 values are different. (If all col3 values are same then distinct will return distinct rows). Here I am expecting the output to be: Any help? Edit When col3 values are same: EDIT

Convert date to ISO week date

How to convert dates to ISO week date in Impala SQL? For example 2019-12-30 in the ISO week date calendar would be written as 2020-W01-1 or 2020W011 ANSWER: Marked Gordon Linoff answer as correct, as it solves the essential part of the question, the deducing of the year part of ISO week date. For the week part of the ISO

Creating entity for database

For example, I have database with table book (id, title, themeId, authorId), table author (id, name) and table theme (id, name). I dont know, should i create entity exactly like in database (and then i will have problems with join queries): or create something like this: in second case i will have problems if authorId or themeId is null (it

Advertisement