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
Count number of students above and below the average score in SQL
I have a sample table below and I am trying to get the number of student above the average score and number of students below the average score. The target result table is supposed to look like I have been able to write a query to get the names of students above the average score and this can be easily
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
Update Oracle SQL Query in a procedure but throwing missing right parenthesis error
The table sc contains the student id and the course id they attended, followed by it’s corresponding grade. The table course contains the course id and corresponding credits The table student1 contains the student id and corresponding info. In this case I need to calculate the average score of every student and add the rank to table student1 The code
How to overcome the problem. If manager is not available then display manager name ‘NA’. If phone number is not available then display as ‘NA’
I have written the query like: Problem is, I’m not getting the output containing null values Answer A regular (inner) join will only return rows that match the join condition. You’re looking for a left join:
Is it possible to use SELECT DISTINCT and GROUP BY together?
Is it possible to use SELECT DISTINCT and GROUP BY clause together? I need DISTINCT to avoid duplicate values and make a single entry of the records, and then get the Total quantity of those duplicate values. For example, I have columns like Item Name and Quantity and their records are (product A,5), (product A,7). Since products are the same
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 a “specific” form of XML, without string concatenation in SQL server T-SQL
I have some weird requirements that demand a specific XML format. Due to short deadlines and my lack of skills I decided to do a fast solution where I generate the XML through string concatenation. and this gives the output which I need. However, I’ve been told numerous times that this is not best practice, and creating XMLs through string
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