Given a table, find the highest marks using INNER JOIN and EXCEPT. It straight forward find marks. Select max(marks) from Students. But how to find highest using INNER JOIN and EXCEPT? Students Table sno name marks 1 A 90 2 B 95 3 C 96 4 D 82 5 E 87 Answer You don’t need to write an INNER JOIN
Tag: mysql
How can I join SQL subqueries as they are?
I have 3 subqueries that when executed independently they all return 3 rows with the desired columns and values. Once I put them all in the from statement and select them all This is the result of all three subqueries being respectively executed standalone Standalone This is the result Snippet above being run…
How to get distinct parent_sku count for the below dataset?
Need your help to extract distinct Parent_sku count from the below data set. Condition: If one child of a parent_sku has “High” sales_tag then that parent_sku count should be excluded from “Low” sales_tag. P.S. Sales_tag column is based on child_sku column. Thank you for your help. Dat…
Faster counts with mysql by sampling table
I’m looking for a way I can get a count for records meeting a condition but my problem is the table is billions of records long and a basic count(*) is not possible as it times out. I thought that maybe it would be possible to sample the table by doing something like selecting 1/4th of the records. I be…
MySQL Combine Group by Column
I am new to SQL statements so my wording per my request may be incorrect, so I will provide a lot of detail to better understand my issue. I have a database table called workouts that looks like this: id bodyPart gifUrl name target broad_target 1 back http://d205bpvrqc9yn1.cloudfront.net/0007.gif alternate la…
MYSQL table wont allow multiple foreign keys
I know this has been asked again and again, and I’ve tried so many times and don’t understand why I keep getting errors, but I’m trying to connect the order details table to the order items, users and payment table, but SQL is coming up with. (this is for a school project) I’ve been ab…
How to keep table name when inner joining related tables
I am new to SQL and wonder how to select nested tables. I have two tables like this: sensors sensor_id model_no location_id int varchar int locations location_id name location radius int varchar point int They are linked with foreign key. Currently, I select using to get the data from both like this: I wonder…
SQL GROUP BY columns with inverted values
Suppose I’ve a table with like this: Where G1, G3 are VARCHAR and G2, G4 are INT If I do a simple GROUP BY on G1..G4 I get: I’m wondering if is possible to aggregate on inverted value G1,G2 <-> G3,G4. What I want to achieve is a result like this: What I tried is to get the inverted rows,
SELECT from Multiple IF conditions in Where Clause
I have a following query In the above query I need to add IF condition that IF a.Type is Accessories then I need certain a.Brands to select from and if a.Type is Clothing then I need to select from certain a.Brands Answer Use a CASE expression, but you should also write a proper join with an ON clause for the
MySQL query to update field in a table based on value of other field in same table
I’ve been trying to figure out the correct query for the following issue and I cannot seem to find the solution myself. I’m running a WooCommerce store which stores a bunch of values as ‘meta_key’ in a MySQL table with the value stored in the ‘meta_value’ column. What I wan…