Search Results

Search found 6276 results on 252 pages for 'join'.

Page 8/252 | < Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >

  • MySQL join headaches, please help!

    - by Andrew Heath
    Ok, I've hit the wall here and need some help. Sample tables are as follows: SCENARIO_NATIONS [scenID] [side] [nation] scen001 1 Germany scen001 2 Britain scen001 2 Canada SCENARIO_NEEDUNITS [scenID] [unitID] scen001 0001 scen001 0003 scen001 0107 scen001 0258 scen001 0759 UNIT_BASIC_DATA [unitID] [nation] [name] 0001 Germany Mortars 0003 Germany Infantry 0107 Britain Lt 0258 Britain Infantry 0759 Canada Kilted Yaksmen Goal: given a scenID, pull a list of units from the database sorted by side, nation, name. I can do everything except for the side inclusion with: SELECT scenario_needunits.scenID, unit_basic_data.nation, unit_basic_data.name FROM scenario_needunits LEFT OUTER JOIN unit_basic_data ON scenario_needunits.unitID=unit_basic_data.unitID WHERE scenario_needunits.scenID='scen001' ORDER BY unit_basic_data.nation ASC, unit_basic_data.name ASC I've tried just dropping the SCENARIO_NATIONS table in as a LEFT OUTER JOIN on scenID but what ends up happening is that ALL units come back with a side of 1 because that's always the first side listed for the scenID in the SCENARIO_NATIONS table. Conceptually, what I think needs to happen is SCENARIO_NATIONS must be joined to both the scenID (to restrict it to just that scenario) and to each unit's nation but I don't have any idea how to do that and my Google-fu is inadequate. :-/

    Read the article

  • 2 Select or 1 Join query ?

    - by xRobot
    I have 2 tables: book ( id, title, age ) ---- 100 milions of rows author ( id, book_id, name, born ) ---- 10 millions of rows Now, supposing I have a generic id of a book. I need to print this page: Title: mybook authors: Tom, Graham, Luis, Clarke, George So... what is the best way to do this ? 1) Simple join like this: Select book.title, author.name From book, author WHERE ( author.book_id = book.id ) AND ( book.id = 342 ) 2) For avoid the join, I could make 2 simple query: Select title FROM book WHERE id = 342 Select name FROM author WHERE book_id = 342 What is the most efficient way ?

    Read the article

  • MySQL Join issue

    - by mouthpiec
    Hi, I have the following tables: --table sportactivity-- sport_activity_id, home_team_fk, away_team_fk, competition_id_fk, date, time (tuple example) - 1, 33, 41, 5, 2010-04-14, 05:40:00 --table teams-- team_id, team_name (tuple example) - 1, Algeria Now I have the following SQL statment that I use to extract Team A vs Team B SELECT sport_activity_id, T1.team_name AS TeamA, T2.team_name AS TeamB, DATE_FORMAT( DATE, '%d/%m/%Y' ) AS DATE, DATE_FORMAT( TIME, '%H:%i' ) AS TIME FROM sportactivity JOIN teams T1 ON home_team_fk = T1.team_id JOIN teams T2 ON ( away_team_fk = T2.team_id OR away_team_fk = '0' ) WHERE DATE( DATE ) >= CURDATE( ) ORDER BY DATE( DATE ) My problem is that when team B is empty, I am having irrelevant information .... it seems that it is returning all the combinations. I need a query that when team B is equal to 0, (this can occur in my scenario) I get only Team A - Team B (as 0) once.

    Read the article

  • mysql join with a "bounce" off a third table

    - by Enkay
    I have 3 mysql tables. companies with company_id and company_name products with product_id and company_id names with product_id, product_name and other info about the product I'm trying to output the product_name and the company_name in one query for a given product_id. Basically I need information from the names and companies tables and the link between them is the products table. How do I do a join that needs to "bounce" off a third table? Something like this but this obviously doesn't work : SELECT product_name, company_name FROM names LEFT OUTER JOIN companies ON (names.product_id = products.product_id and products.company_id = companies.company_id) WHERE product_id = '12345' Thanks!

    Read the article

  • group_concat on an empty join in MySQL

    - by Yossarian
    Hello, I've got the following problem: I have two tables: (simplified) +--------+ +-----------+ | User | | Role | +--------+ +-----------+ | ID<PK> | | ID <PK> | +--------+ | Name | +-----------+ and M:N relationship between them +-------------+ | User_Role | +-------------+ | User<FK> | | Role<FK> | +-------------+ I need to create a view, which selects me: User, and in one column, all of his Roles (this is done by group_concat). I've tried following: SELECT u.*, group_concat(r.Name separator ',') as Roles FROM User u LEFT JOIN User_Role ur ON ur.User=u.ID LEFT JOIN Role r ON ur.Role=r.ID GROUP BY u.ID; However, this works for an user with some defined roles. Users without role aren't returned. How can I modify the statement, to return me User with empty string in Roles column when User doesn't have any Role? Explanation: I'm passing the SQL data directly to a grid, which then formats itself, and it is easier for me to create slow and complicated view, than to format it in my code. I'm using MySQL

    Read the article

  • Oracle curcular join sometimes give duplicates, but sometimes does not

    - by Kaushik
    By mistake I wrote a query like this: select * from a,b,c where a.col=b.col and b.col2=c.col2 and c.col3=a.col4 So there is a circular join here. Now the thing is sometimes this query returns duplicate result, sometimes it returns unique(correct) results. I am trying to understand why it does not give duplicate results always. Also if circular joins are not allowed, how come Oracle does not throw an error. EDIT: This is the actual query. After reading ti carefully, I am not sure anymore if this is a circular join or not.It does not seem so...but why I get duplicates only sometime? select * from a,b,c,d where a.col=b.col and b.col=c.col and c.col2=d.col2 and d.col2 =a.col2

    Read the article

  • Broken count(*) after adding LEFT JOIN

    - by Iain Urquhart
    Since adding the LEFT JOIN to the query below, the count(*) has been returning some strange values, it seems to have added the total rows returned in the query to the 'level': SELECT `n`.*, exp_channel_titles.*, round((`n`.`rgt` - `n`.`lft` - 1) / 2, 0) AS childs, count(*) - 1 + (`n`.`lft` > 1) + 1 AS level, ((min(`p`.`rgt`) - `n`.`rgt` - (`n`.`lft` > 1)) / 2) > 0 AS lower, (((`n`.`lft` - max(`p`.`lft`) > 1))) AS upper FROM `exp_node_tree_6` `n` LEFT JOIN `exp_channel_titles` ON (`n`.`entry_id`=`exp_channel_titles`.`entry_id`), `exp_node_tree_6` `p`, `exp_node_tree_6` WHERE `n`.`lft` BETWEEN `p`.`lft` AND `p`.`rgt` AND ( `p`.`node_id` != `n`.`node_id` OR `n`.`lft` = 1 ) GROUP BY `n`.`node_id` ORDER BY `n`.`lft` I'm totally stumped... Thank you!

    Read the article

  • MySQL Join Comma Separated Field

    - by neeraj
    I have two tables. First Table is a batch table that contain comma separated student id in field "batch" batch -------------- id batch -------------- 1 1,2 2 3,4 Second Table is marks marks ---------------------- id studentid subject marks 1 1 English 50 2 2 English 40 3 3 English 70 4 1 Math 65 5 4 English 66 6 5 English 75 7 2 Math 55 How we can find those students of first batch id =1 who have scored more than 45 marks in English without using sub query. Problem i found to get this done using a single query is that we can not use IN as an association operator in JOIN statement What changes are required in below query to make it work? SELECT * FROM batch INNER JOIN marks ON marks.studentid IN(batch.batch) where batch.id = 1

    Read the article

  • C# LINQ join With Just One Row

    - by Soo
    I'm trying to make a query that grabs a single row from an SQL database and updates it. TableA AId AValue TableB BId AId BValue Ok, so TableA and TableB are linked by AId. I want to select a row in TableB based on AValue using a join. The following query is what I have and only grabs a value from TableB based on AId, I just don't know how to grab a row from TableB using AValue. I know you would need to use a join, but I'm not sure how to accomplish that. var row = DbObject.TableB.Single(x => x.AId == 1) row.BValue = 1; DbObject.SubmitChanges();

    Read the article

  • MySQL AND alternative for eatch table in a join

    - by Scott
    I have a simple join in a query however I need to have a condition on both of the tables "confirmed='yes'" but if one of the tables doesn't have any that match the query returns with no rows. Database: .----------parties----------. | id - party_id - confirmed | |---------------------------| | 1 1 yes | | 1 2 no | | 1 3 no | +---------------------------+ .-----------events----------. | id - event_id - confirmed | |---------------------------| | 1 1 no | +---------------------------+ Query: SELECT p.party_id, e.event_id FROM parties p LEFT JOIN events e ON p.id=e.id WHERE p.id = '1' AND p.party_id IN (1,2,3) AND e.event_id IN (1) AND p.confirmed='yes' AND e.confirmed='yes' It returns nothing but I want it to return party_id 1 with a empty event_id. I hope this make sense and I not missing anything, Thanks for your help!

    Read the article

  • mysql select multiple rows in join

    - by julio
    Hi-- I have a simple mySQL problem-- I have two tables, one is a user's table, and one is a photos table (each user can upload multiple photos). I'd like to write a query to join these tables, so I can pull all photos associated with a user (up to a certain limit). However, when I do something obvious like this: SELECT *.a, *.b FROM user_table a JOIN photos_table b ON a.id = b.userid it returns a.id, a.name, a.email, a.address, b.id, b.userid, b.photo_title, b.location but it only returns a single photo. Is there a way to return something like: a.id, a.name, a.email, a.address, b.id, b.userid, b.photo_title, b.location, b.id2, b.photo_title2, b.location2 etc. . . for a given LIMIT of photos? Thanks for any ideas.

    Read the article

  • MySQL AND alternative for each table in a join

    - by Scott
    I have a simple join in a query however I need to have a condition on both of the tables "confirmed='yes'" but if one of the tables doesn't have any that match the query returns with no rows. Database: .----------parties----------. | id - party_id - confirmed | |---------------------------| | 1 1 yes | | 1 2 no | | 1 3 no | +---------------------------+ .-----------events----------. | id - event_id - confirmed | |---------------------------| | 1 1 no | +---------------------------+ Query: SELECT p.party_id, e.event_id FROM parties p LEFT JOIN events e ON p.id=e.id WHERE p.id = '1' AND p.party_id IN (1,2,3) AND e.event_id IN (1) AND p.confirmed='yes' AND e.confirmed='yes' It returns nothing but I want it to return party_id 1 with a empty event_id. I hope this make sense and I not missing anything, Thanks for your help!

    Read the article

  • Join and sum not compatible matrices through data.table

    - by leodido
    My goal is to "sum" two not compatible matrices (matrices with different dimensions) using (and preserving) row and column names. I've figured this approach: convert the matrices to data.table objects, join them and then sum columns vectors. An example: > M1 1 3 4 5 7 8 1 0 0 1 0 0 0 3 0 0 0 0 0 0 4 1 0 0 0 0 0 5 0 0 0 0 0 0 7 0 0 0 0 1 0 8 0 0 0 0 0 0 > M2 1 3 4 5 8 1 0 0 1 0 0 3 0 0 0 0 0 4 1 0 0 0 0 5 0 0 0 0 0 8 0 0 0 0 0 > M1 %ms% M2 1 3 4 5 7 8 1 0 0 2 0 0 0 3 0 0 0 0 0 0 4 2 0 0 0 0 0 5 0 0 0 0 0 0 7 0 0 0 0 1 0 8 0 0 0 0 0 0 This is my code: M1 <- matrix(c(0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0), byrow = TRUE, ncol = 6) colnames(M1) <- c(1,3,4,5,7,8) M2 <- matrix(c(0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0), byrow = TRUE, ncol = 5) colnames(M2) <- c(1,3,4,5,8) # to data.table objects DT1 <- data.table(M1, keep.rownames = TRUE, key = "rn") DT2 <- data.table(M2, keep.rownames = TRUE, key = "rn") # join and sum of common columns if (nrow(DT1) > nrow(DT2)) { A <- DT2[DT1, roll = TRUE] A[, list(X1 = X1 + X1.1, X3 = X3 + X3.1, X4 = X4 + X4.1, X5 = X5 + X5.1, X7, X8 = X8 + X8.1), by = rn] } That outputs: rn X1 X3 X4 X5 X7 X8 1: 1 0 0 2 0 0 0 2: 3 0 0 0 0 0 0 3: 4 2 0 0 0 0 0 4: 5 0 0 0 0 0 0 5: 7 0 0 0 0 1 0 6: 8 0 0 0 0 0 0 Then I can convert back this data.table to a matrix and fix row and column names. The questions are: how to generalize this procedure? I need a way to automatically create list(X1 = X1 + X1.1, X3 = X3 + X3.1, X4 = X4 + X4.1, X5 = X5 + X5.1, X7, X8 = X8 + X8.1) because i want to apply this function to matrices which dimensions (and row/columns names) are not known in advance. In summary I need a merge procedure that behaves as described. there are other strategies/implementations that achieve the same goal that are, at the same time, faster and generalized? (hoping that some data.table monster help me) to what kind of join (inner, outer, etc. etc.) is assimilable this procedure? Thanks in advance. p.s.: I'm using data.table version 1.8.2 EDIT - SOLUTIONS @Aaron solution. No external libraries, only base R. It works also on list of matrices. add_matrices_1 <- function(...) { a <- list(...) cols <- sort(unique(unlist(lapply(a, colnames)))) rows <- sort(unique(unlist(lapply(a, rownames)))) out <- array(0, dim = c(length(rows), length(cols)), dimnames = list(rows,cols)) for (m in a) out[rownames(m), colnames(m)] <- out[rownames(m), colnames(m)] + m out } @MadScone solution. Used reshape2 package. It works only on two matrices per call. add_matrices_2 <- function(m1, m2) { m <- acast(rbind(melt(M1), melt(M2)), Var1~Var2, fun.aggregate = sum) mn <- unique(colnames(m1), colnames(m2)) rownames(m) <- mn colnames(m) <- mn m } BENCHMARK (100 runs with microbenchmark package) Unit: microseconds expr min lq median uq max 1 add_matrices_1 196.009 257.5865 282.027 291.2735 549.397 2 add_matrices_2 13737.851 14697.9790 14864.778 16285.7650 25567.448 No need to comment the benchmark: @Aaron solution wins. I'll continue to investigate a similar solution for data.table objects. I'll add other solutions eventually reported or discovered.

    Read the article

  • Hibernate Criteria: Perform JOIN in Subquery/DetachedCriteria

    - by Gilean
    I'm running into an issue with adding JOIN's to a subquery using DetachedCriteria. The code looks roughly like this: Criteria criteria = createCacheableCriteria(ProductLine.class, "productLine"); criteria.add(Expression.eq("productLine.active", "Y")); DetachedCriteria subCriteria = DetachedCriteria.forClass(Models.class, "model"); subCriteria.setProjection(Projections.rowCount()); subCriteria.createAlias("model.language", "modelLang"); criteria.add(Expression.eq("modelLang.language_code", "EN")); subCriteria.add(Restrictions.eqProperty("model.productLine.id","productLine.id")); criteria.add(Subqueries.lt(0, subCriteria)); But the logged SQL does not contain the JOIN in the subquery, but does include the alias which is throwing an error SELECT * FROM PRODUCT_LINES this_ WHERE this_.ACTIVE=? AND ? < (SELECT COUNT(*) AS y0_ FROM MODELS this0__ WHERE modelLang3_.LANGUAGE ='EN' AND this0__.PRODUCT_LINE_ID =this_.ID ) How can I add the joins to the DetachedCriteria? Hibernate version: 3.2.6.ga Hibernate core: 3.3.2.GA Hibernate annotations: 3.4.0.GA Hibernate commons-annotations: 3.3.0.ga Hibernate entitymanager: 3.4.0.GA Hibernate validator: 3.1.0.GA

    Read the article

  • solr JOIN query

    - by Sfairas
    I need to run a JOIN query on a solr index. I've got two xmls that I have indexed, person.xml and subject.xml. Person: <doc> <field name="id">P39126</field> <field name="family">Smith</field> <field name="given">John</field> <field name="subject">S1276</field> <field name="subject">S1312</field> </doc> Subject: <doc> <field name="id">S1276</field> <field name="topic">Abnormalities, Human</field> </doc> I need to only display information from the person doc but each query should match fields in both person and subject. In the case the query matches only the subject doc I need to display all docs from the person that have a matching id. Is this possible to do without running two seperate queries? Something like a JOIN query would do the job. Any help?

    Read the article

  • Linq join with an inner collection

    - by bronze
    Hi, I am trying a LINQ to Object query on 2 collections Customer.Orders Branches.Pending.Orders (Collection within a collection) I want to output each branch which is yet to deliver any order of the customer. var match = from order in customer.Orders join branch in Branches on order equals branch.Pending.Orders select branch; This does not work, I get : The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'GroupJoin'. From my search, I think this is because Order or collection of Orders does not implement equals. If this query worked, it will still be wrong, as it will return a branch if the customer's and pending orders match exactly. I want a result if any of the order matches. I am learning Linq, and looking for a approach to address such issues, rather than the solution itself. I would have done this in SQL like this; SELECT b.branch_name from Customers c, Branches b, Orders o WHERE c.customer_id = o.customer_id AND o.branch_id = b.branch_id AND c.customer_id = 'my customer' AND o.order_status = 'pending'

    Read the article

  • using a JOIN in an UPDATE in SQL

    - by SDLFunTimes
    Hi, I'm having trouble formulating a legal statement to double the statuses of the suppliers (s) who have shipped (sp) more than 500 units. I've been trying: update s set s.status = s.status * 2 from s join sp on (sp.sno = s.sno) group by sno having sum(qty) > 500; however I'm getting this error from Mysql: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from s join sp on (sp.sno = s.sno) group by sno having sum(qty) > 500' at line 1 Does anyone have any ideas about what is wrong with this query? Here's my schema: create table s ( sno char(5) not null, sname char(20) not null, status smallint, city char(15), primary key (sno) ); create table p ( pno char(6) not null, pname char(20) not null, color char(6), weight smallint, city char(15), primary key (pno) ); create table sp ( sno char(5) not null, pno char(6) not null, qty integer not null, primary key (sno, pno) );

    Read the article

  • SQL statement to split a table based on a join

    - by williamjones
    I have a primary table for Articles that is linked by a join table Info to a table Tags that has only a small number of entries. I want to split the Articles table, by either deleting rows or creating a new table with only the entries I want, based on the absence of a link to a certain tag. There are a few million articles. How can I do this? Not all of the articles have any tag at all, and some have many tags. Example: table Articles primary_key id table Info foreign_key article_id foreign_key tag_id table Tags primary_key id It was easy for me to segregate the articles that do have the match right off the bat, so I thought maybe I could do that and then use a NOT IN statement but that is so slow running it's unclear if it's ever going to finish. I did that with these commands: INSERT INTO matched_articles SELECT * FROM articles a LEFT JOIN info i ON a.id = i.article_id WHERE i.tag_id = 5; INSERT INTO unmatched_articles SELECT * FROM articles a WHERE a.id NOT IN (SELECT m.id FROM matched_articles m); If it makes a difference, I'm on Postgres.

    Read the article

  • Filtering on a left join in SQLalchemy

    - by Adam Ernst
    Using SQLalchemy I want to perform a left outer join and filter out rows that DO have a match in the joined table. I'm sending push notifications, so I have a Notification table. This means I also have a ExpiredDeviceId table to store device_ids that are no longer valid. (I don't want to just delete the affected notifications as the user might later re-install the app, at which point the notifications should resume according to Apple's docs.) CREATE TABLE Notification (device_id TEXT, time DATETIME); CREATE TABLE ExpiredDeviceId (device_id TEXT PRIMARY KEY, expiration_time DATETIME); Note: there may be multiple Notifications per device_id. There is no "Device" table for each device. So when doing SELECT FROM Notification I should filter accordingly. I can do it in SQL: SELECT * FROM Notification LEFT OUTER JOIN ExpiredDeviceId ON Notification.device_id = ExpiredDeviceId.device_id WHERE expiration_time == NULL But how can I do it in SQLalchemy? sess.query( Notification, ExpiredDeviceId ).outerjoin( (ExpiredDeviceId, Notification.device_id == ExpiredDeviceId.device_id) ).filter( ??? ) Alternately I could do this with a device_id NOT IN (SELECT device_id FROM ExpiredDeviceId) clause, but that seems way less efficient.

    Read the article

  • JOIN (SELECT DISTINCT [..] substitute

    - by FRKT
    Hello, I'd like to find a substitute for using SELECT DISTINCT in a derived table. Let's say I have three tables: CREATE TABLE `trades` ( `tradeID` int(11) unsigned NOT NULL AUTO_INCREMENT, `employeeID` int(11) unsigned NOT NULL, `corporationID` int(11) unsigned NOT NULL, `profit` int(11) NOT NULL, KEY `tradeID` (`tradeID`), KEY `employeeID` (`employeeID`), KEY `corporationID` (`corporationID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 CREATE TABLE `corporations` ( `corporationID` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, PRIMARY KEY (`corporationID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 CREATE TABLE `employees` ( `employeeID` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, PRIMARY KEY (`employeeID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 Let's say I'd like to find out how much profit a specific employee has generated. Simple: SELECT SUM(profit) FROM trades JOIN employees ON trades.employeeID = employees.employeeID AND employees.employeeID = 1; It gets trickier if I'd like to query how much revenue a specific corporation has, however. I cannot simply replicate the aforementioned query, because two or more employees from the same company might be involved in the same trade. This query should do the trick: SELECT SUM(profit) FROM trades JOIN (SELECT DISTINCT tradeID FROM trades WHERE trades.corporationID = 1) ... unfortunately, DISTINCT JOINs seem crazy ineffective. Is there any alternative I can use to determine how much revenue a corporation has, taking into account that a corporation might be listed several times with the same tradeID?

    Read the article

  • Hibernate HQL m:n join problem

    - by smallufo
    I am very unfamiliar with SQL/HQL , and am currently stuck with this 'maybe' simple problem : I have two many-to-many Entities , with a relation table : Car , CarProblem , and Problem . One Car may have many Problems , One Problem may appear in many Cars, CarProblem is the association table with other properties . Now , I want to find Car(s) with specified Problem , how do I write such HQL ? All ids are Long type . I've tried a lot of join / inner-join combinations , but all in vain.. -- updated : Sorry , forget to mention : Car has many CarProblem Problem has many CarProblem Car and Problem are not directly connected in Java Object. -- update , java code below -- @Entity public class Car extends Model{ @OneToMany(mappedBy="car" , cascade=CascadeType.ALL) public Set<CarProblem> carProblems; } @Entity public class CarProblem extends Model{ @ManyToOne public Car car; @ManyToOne public Problem problem; ... other properties } @Entity public class Problem extends Model { other properties ... // not link to CarProblem , It seems not related to this problem // **This is a very stupid query , I want to get rid of it ...** public List<Car> findCars() { List<CarProblem> list = CarProblem.find("from CarProblem as cp where cp.problem.id = ? ", id).fetch(); Set<Car> result = new HashSet<Car>(); for(CarProblem cp : list) result.add(cp.car); return new ArrayList<Car>(result); } } The Model is from Play! framework , so these properties are all public .

    Read the article

  • SQL Standard Regarding Left Outer Join and Where Conditions

    - by Ryan
    I am getting different results based on a filter condition in a query based on where I place the filter condition. My questions are: Is there a technical difference between these queries? Is there anything in the SQL standard that explains the different resultsets in the queries? Given the simplified scenario: --Table: Parent Columns: ID, Name, Description --Table: Child Columns: ID, ParentID, Name, Description --Query 1 SELECT p.ID, p.Name, p.Description, c.ID, c.Name, c.Description FROM Parent p LEFT OUTER JOIN Child c ON (p.ID = c.ParentID) WHERE c.ID IS NULL OR c.Description = 'FilterCondition' --Query 2 SELECT p.ID, p.Name, p.Description, c.ID, c.Name, c.Description FROM Parent p LEFT OUTER JOIN Child c ON (p.ID = c.ParentID AND c.Description = 'FilterCondition') I assumed the queries would return the same resultsets and I was surprised when they didn't. I am using MS SQL2005 and in the actual queries, query 1 returned ~700 rows and query 2 returned ~1100 rows and I couldn't detect a pattern on which rows were returned and which rows were excluded. There were still many rows in query 1 with child rows with data and NULL data. I prefer the style of query 2 (and I think it is more optimal), but I thought the queries would return the same results.

    Read the article

  • Left Join only returning one row

    - by Adam
    I am trying to join two tables. I would like all the columns from the product_category table (there are a total of 6 now) and count the number of products, CatCount, that are in each category from the products_has_product_category table. My query result is 1 row with the first category and a total count of 68, when I am looking for 6 rows with each individual category's count. <?php $result = mysql_query(" SELECT a.*, COUNT(b.category_id) AS CatCount FROM `product_category` a LEFT JOIN `products_has_product_category` b ON a.product_category_id = b.category_id "); while($row = mysql_fetch_array($result)) { echo ' <li class="ui-shadow" data-count-theme="d"> <a href="' . $row['product_category_ref_page'] . '.php" data-icon="arrow-r" data-iconpos="right">' . $row['product_category_name'] . '</a><span class="ui-li-count">' . $row['CatCount'] . '</span></li>'; } ?> I have been working on this for a couple of hours and would really appreciate any help on what I am doing wrong.

    Read the article

  • Oracle - Update statement with inner join

    - by user169743
    I have a query which works fine in MySQL, I'm trying to get it working on oracle but get the following error SQL Error: ORA-00933: SQL command not properly ended 00933. 00000 - "SQL command not properly ended" The query is: UPDATE table1 INNER JOIN table2 ON table1.value = table2.DESC SET table1.value = table2.CODE WHERE table1.UPDATETYPE='blah'; I'd be extremely grateful for any help.

    Read the article

  • SQL is this equvelent to a LEFT JoIn?

    - by Jim
    Is this equvelent to a LEFT JOIN? select distinct a.name, b.name from tableA a, (select name from tableB) as b It seems as though there is no link between the two tables. Is there an easier / more efficient way to write this?

    Read the article

< Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >