inner-join

SQL Server : join on uniqueidentifier

十年热恋 提交于 2019-12-13 00:58:56
问题 I have two tables Backup and Requests . Below is the script for both the tables Backup CREATE TABLE UserBackup( FileName varchar(70) NOT NULL, ) File name is represented by a guid. Sometimes there is some additional information related to the file. Hence we have entries like guid_ADD entried in table. Requests CREATE TABLE Requests( RequestId UNIQUEIDENTIFIER NOT NULL, Status int Not null ) Here are some sample rows : UserBackup table: FileName 15b993cc-e8be-405d-bb9f-0c58b66dcdfe 4cffe724

Return results of query based on todays date in SQL (MySQL) Part 2

久未见 提交于 2019-12-13 00:46:47
问题 I posted another question which was resolved perfectly however I now need to apply the same code I was given to a different piece of MySQL code. What I have is SELECT value, COUNT(*) AS 'num' FROM table_c WHERE table_c_id IN (9, 17, 25) GROUP BY value What I would like to do now is only show the results if they have been entered on the current date? The current code snippet I have for checking the current date, which works great is (the date is in unixtime format) ( xxxxxxxxxxxxxx and curdate

How do we do LEFT JOIN with old syntax?

与世无争的帅哥 提交于 2019-12-12 19:26:37
问题 How do we do LEFT JOIN with old syntax? Let's say you have a User table and UserRole table, and you are holding the ID of the UserRole in User table. Here is the query to retrieve all User's names, and the Role Names with the new notation: SELECT U.Username, US.[Desc] FROM [User] U INNER JOIN UserRole US ON U.UserRoleId = US.Id And here is the old notation: SELECT U.Username, US.[Desc] FROM [User] U, UserRole US WHERE U.UserRoleId = US.Id Now, let's assume that all users don't have a role,

How can I force LINQ to SQL to perform an INNER JOIN on a nullable foreign key?

二次信任 提交于 2019-12-12 17:40:46
问题 I have a very simple set-up. Table "Node" has a nullable foreign key "ObjectId." This is represented in my database model with a one-to-many association. Now, I want to run a query that gives me all Node-Objects with a particular object id. In straight SQL, this is very easy: SELECT Node.*, Object.* FROM Node INNER JOIN Object ON Node.ObjectId = Object.ObjectId WHERE Node.ObjectId = @objectId But now I want to do the same thing in LINQ to SQL: private static Func<MyDataContext, string,

Query optimisation

主宰稳场 提交于 2019-12-12 17:23:34
问题 In my application, my module uses the following tables PUBLIC_APPLICATION CATEGORY_MASTER NOTIFICATION_SITE_DETAIL DIMENSION_MASTER DM PUBLIC_REGISTRATION ALLOTMENT_NOTIFICATION. From the following tables I am retrieving the data SELECT PA.REGISTRATION_NO,PA.APP_ID,PA.NO_OF_ATTEMPTS,CM.CATEGORY_NAME, DM.SITE_DIMENSION,PR.BDA_NO,AN.NOTIFY_ID FROM **PUBLIC_APPLICATION PA,CATEGORY_MASTER CM,NOTIFICATION_SITE_DETAIL NSD,DIMENSION_MASTER DM, PUBLIC_REGISTRATION PR,ALLOTMENT_NOTIFICATION AN** WHERE

Passing sql variables from INNER JOIN SQL query to PHP script

女生的网名这么多〃 提交于 2019-12-12 14:50:13
问题 I have the following INNER JOIN query: SELECT b.*, c.date2 FROM ( SELECT a.work, a.amount, COUNT(*) totalCount, SUM(Amount) totalAmount FROM work_times a WHERE Organisation=? GROUP BY a.work, a.amount ) b INNER JOIN ( SELECT a.work, a.amount, DATE_FORMAT(Date,'%D %M %Y') date2, date FROM work_times a ) c ON b.work = c.work and b.amount=c.amount ORDER BY b.work, b.totalCount, c.date You can see it in action on a sample table on SQL fiddle here. My aim is to return the following: 5 consultancy

MySQL select distinct products from 3 tables

狂风中的少年 提交于 2019-12-12 10:57:32
问题 MySQL select from 3 tables. I have these 5 tables: CREATE TABLE `category` ( `c_id` int(6) NOT NULL AUTO_INCREMENT, `name` varchar(40) NOT NULL, PRIMARY KEY (c_id) ); CREATE TABLE `product` ( `p_id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(40) NOT NULL, `brand` varchar(30) NOT NULL, `image_path` varchar(100) DEFAULT NULL, PRIMARY KEY (p_id) ); CREATE TABLE `shop` ( `s_id` int(6) NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL, `country` varchar(30) NOT NULL, `province` varchar(30)

How to left join or inner join a table itself

夙愿已清 提交于 2019-12-12 10:54:39
问题 I have this data in a table, for instance, id name parent parent_id 1 add self 100 2 manage null 100 3 add 10 200 4 manage null 200 5 add 20 300 6 manage null 300 How can I left join or inner join this table itself so I get this result below? id name parent 2 manage self 4 manage 10 6 manage 20 As you can I that I just want to query the row with the keyword of 'manage' but I want the column parent 's data in add 's row as the as in manage 's row in the result. Is it possible? EDIT: the

Sql query to get data diffrence of total in 2 tables

瘦欲@ 提交于 2019-12-12 06:52:42
问题 I have two tables: booking - records the order detail id | booking_amount ------------------- 1 | 150 2 | 500 3 | 400 payment - records the payment for order id | booking_id | amount ------------------------ 1 | 1 | 100 2 | 1 | 50 2 | 2 | 100 I want to find all bookings where the payments are not complete. With the above data, we expect the answer to be 2,3 , because the sum of payments for booking_id=1 matches the corresponding booking_amount in the booking_table . 回答1: To answer your

Using Row_number() OVER(partition BY..) along with declaring local variables

岁酱吖の 提交于 2019-12-12 06:07:23
问题 I have a sql query, in this sql query I want to select distinct columns irrespective of column first. For other sql query I use Row_number() OVER(partition BY..) and I also need to use inner join. The query in which I want to use row_number and inner join is - DECLARE @columns NVARCHAR(MAX) DECLARE @params NVARCHAR(MAX) = '@columns NVARCHAR(MAX) OUTPUT' DECLARE @sql NVARCHAR(MAX) = 'SELECT @columns = STUFF( ( SELECT '',''+ [column_name] FROM information_schema.columns WHERE (table_schema = '