inner-join

Querying on count value having ()

I'm having difficulty with a query which displays records according to their fill rate. For instance, a vacancy can have no bookings or some bookings. If a vacancy has bookings, they can be in the form of 'active [1]', 'pending [0]'. The query I have written so far works if the vacancy has booking records but I can't get it to work if ...

SQL: Finding duplicate values in a field, but using SubString()

Here's a question for all those SQL SERVER 2000 experts: I have only 1 table... I can already find if any of the values in a certain field, also appears in another record. I.E.: Does any record have "ABCDEFGHI" in a field, and then "ABCDEFGHI" again in that same field... but in another record. But I run into trouble when I...

Entity Framework 4 INNER JOIN help

Hello, Can anyone tell me how to write the following query in Entity Framework 4.0? "Blogs" and "Categories" are my entities. The query basically returns me the list of categories and the number of blogs that are in that category. SELECT b.CategoryId, c.Value, Count(b.Id) AS [Count] FROM dbo.Blogs b INNER JOIN dbo.Categories c ON b.Cat...

Adding an INNER JOIN to a query should not increase the number of rows returned right?

Hi, I have a query like the following that returns the correct number of rows that I would expect. (It has to match a similar query that returns the same data sets but with different associated info from other related tables. SELECT * FROM LK INNER JOIN STC ON LK.V = STC.VI LEFT OUTER JOIN BC ON LK.BC = BC.ID LEFT OUTER JOIN K AS LT ON ...

mysql inner join statement and memory overuse !

hey guys im running bellow query to fetch from 3 mysql tables and it works fine but it increases memory usage and sometime it takes 10 seconds to start loading the page INNER JOIN table_tags AS ntg ON (ns.tags = '' OR CONCAT(' ',COALESCE(ns.tags,' '),' ') LIKE CONCAT('% ',ntg.tid,' %')) INNER JOIN table_topics AS nto ON (ns.asso...

How to join two tables mysql?

Hello friends, I have two tables: services id client service and clients id name email How to list table service and bring together the customer name that the customers table? field customer services in the table has the id of the customer at the customer table, I appreciate the help from you now ...

CakePHP tables join help

Hi folks, new to cakePHP and trying my first join. I've got one table called users and one called projects. one user can have many projects, so projects has a user_id column. Here is my action in projects_controller: function index() { $this->set('projects', $this->Project->find('all', array('joins' => array( array( ...

Fight against INNER JOINS - Chapter: unknown column

SELECT p.id FROM produkty p, przyporzadkowania pr, stany_magazynowe, gk_grupy_produkty INNER JOIN sub_subkategorie ssi ON pr.sub_subkategorie_id = ssi.ID Tables and their important fields produkty - id, pozycja przyporzadkowania - id, produkt_id, sub_kategoria_id, sub_subkategoria_id sub_subkategorie - id, subkategorie_id, pozycja sub...

inner join Vs Function

Hi all, Which of the following query is better... This is just an example, there are numerous situations, where I want the user name to be displayed instead of UserID Select EmailDate, B.EmployeeName as [UserName], EmailSubject from Trn_Misc_Email as A inner join Mst_Users as B on A.CreatedUserID = B.EmployeeLog...

MySQL problem involving crazy multiple self-joins

As part of the process of replacing some old code that used an incredibly slow nested select, I've ended up with a query that looks like this: SELECT r3.r_id AS r3_id, r2.r_id AS r2_id, r1.r_id AS r1_id FROM table_r r3 LEFT JOIN ( table_r r2 INNER JOIN ( table_r r1 INNER JOIN table_d d ON r1.r_id = d.r_id ) ON r2.r_id = r1...

performing select count across two tables sql

I have a table relationship which links one person to many relatives. so the tables are 1. Client. 2. Client_relative. I want to display all the rows of the Persons table, while displaying a count of how many relatives each person has. I have this query: SELECT c.clientid, c.fname, c.lname, count(cr.relativeid) as relativecount FROM {c...

Sql - struggling with count/having query based on several joins

Hi, I'm struggling to get my query working. Basically, what it should do is only return vacancies that haven't been filled. For example, a vacancy can have a pre-determined limit of 5. To fill this, it will need to have a mixture of 5 active or pending bookings or simply 5 active or 5 pending bookings. A pending booking is changed to a...

inner join... how to get all fields from one table ?

Hi, I want to get all fields from one table and use DISTINCT with the second table. I have this: SELECT stats.*, DISTINCT(visit_log.blog_id) AS bid FROM stats INNER JOIN visit_log ON stats.blog_id = visit_log.blog_id But I get this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL se...

INNER JOIN DISTINCT with MySQL

I have a mysql problem. I have two tables like this that I need to join together. table: id otherid2 1 | 1 2 | 1 3 | 2 4 | 2 table2: otherid otherid2 1 | 1 2 | 1 3 | 2 4 | 2 I'm using: SELECT id,otherid FROM table INNER JOIN table2 ON table.otherid2=table2.otherid2 Th...

How to change this SQL so that I can get one post from each author?

In the sql below I have the last 5 posts. But sometimes these posts are from the same author. I want to select the last 5 but just one per author. SELECT `e` . * , `f`.`title` AS `feedTitle` , `f`.`url` AS `feedUrl` , `a`.`id` AS `authorId` , `a`.`name` AS `authorName` , `a`.`about` AS `authorAbou...

mysql complex update and replace

Hey everyone, I've got an interesting query that I wonder if anyone can help with? Basically, I have three tables, Title, Attribute and Attribute_Value Title contains a list of templates like 'Created on {Date} by {User} in {Category}' then in the Attribute table, I have rows that contain a definition of the parameters wrapped in cur...

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

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 O...

SQL count query not returning correct results

Struggling getting a query to work…….. I have two tables:- tbl.candidates: candidate_id agency_business_unit_id tbl.candidate_employment_tracker candidate_id The candidate employment can have duplicate records of a candidate_id as it contains records on their working history for different clients. The candidates tables is unique f...

Export a MySQL table via JOIN?

Hey guys..... I was wondering if rather than creating another table to store the results of the MySQL JOIN query is it possible to just export a queries result.... like to a CSV? The query for example would be something like this.. SELECT us.id, CONCAT_WS(' - ',cats_sic_us.sic,cats_sic_us.category) AS sic_cat FROM us I...

Opposite Of An Inner Join Query

can someone help me write sql for a scernerio like this: Table 1 2 columns: ID, Name Table 2 2 columns: ID, Name I want a query to show names from Table 1 that are not in table 2. So filter out all the names in table 1 that are in table 2 is the result query. Use ID for the filtering not name. This will help me in what I am tryin...