Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    MYSQL




Select Statement With Multiple Counts/multiple Joins Trouble


SQL
SELECT g.group_id, g.name, g.description, g.icon, g.user_id, g.date, u.username, count(c.comment_id) as comment_count, count(v.video_id) as video_count, count(m.user_id) as user_count
FROM duo_groups as g
LEFT JOIN duo_group_members as m on m.group_id=g.group_id
LEFT JOIN duo_users as u on u.user_id=m.user_id
LEFT JOIN duo_videos as v ON g.group_id=v.group_id
LEFT JOIN duo_video_comments as c on v.video_id=c.video_id
GROUP BY g.group_id, g.name, g.description, g.icon, g.user_id, g.date, u.username
Will return

My current problem with the above statement is with the counts. The count is accurate when only one of the counts is returned. However when more than 1 of the counts is returned the other counts (if they are not 0) will return the same number. For example look at the screenshot above. The first row, all three counts are the same but they are not accurate. They alll point to 8 because there are 8 comments, but there aren't 8 videos or 8 users. Same with the second row. There aren't 2 users only 2 videos.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Multiple Counts And Joins
SELECT
tin.traffic_referer,
COUNT( tin.traffic_referer ) AS hits_in,
COUNT( tout.traffic_page ) AS hits_out
FROM traffic_in tin
LEFT JOIN traffic_out tout
ON tout.traffic_referer = tin.traffic_referer
GROUP BY tin.traffic_referer, tout.traffic_page
LIMIT 0 , 30
That's the code I'm trying to use but the result sets are coming up weird.

If theres no hits out then the results come up like they should:

http://babelfish.altavista.com | 6 | 0
But if there are any hits out then the results come up like this:

http://forum.phap.net | 6314 | 6314
The hits_in and hits_out always come up the same.

Multiple Table Joins In A Select
How do I write a select query to join more than two tables? =20

Table A relates to table B and table B relates to Table C.

I need to return fields from Table A and C that are related..

Multiple Table Joins In A Select
How do I write a select query to join more than two tables? =20

Table A relates to table B and table B relates to Table C.

I need to return fields from Table A and C that are related.

Joins With Multiple Tables And Multiple Rows
I'm making a good ol' forum, and i have three tables, users, threads
and posts. when i query my threads table with a join, i need to access
the users table twice to get the username of the first poster and last
poster. But how? I can only figure out how to get one or the other. Is
my design bad? eg

SELECT TopicID, FirstPostID, LastPostID, Replies, Views, Topic,
username FROM DiscussionThreads, users WHERE
DiscussionThreads.FirstPostID=users.ID ORDER BY FirstPostDT DESC LIMIT
10 .

Multiple Counts
Having some trouble with the query below.

select a.advisor_ao as 'AO',
case c.existing_client when 'feps' then count(c.existing_client) else 0 end as 'total'
from advisor_tb a left join company_tb b on a.advisor_id = b.advisor_id
left join comp_seminar_ca_tb c on b.company_id = c.company_id
group by a.advisor_ao

the existing_client field is varchar and contains values in numbers and text. It seems to be returning 0 at all times. But when i set the criteria to 0 and not FEPs that is the only time i get any kind of results.

I am not asking for an answer i just wanted to know if my query is incorrect because it is then i have to work on my table structure.

Multiple COUNT() In SELECT Statement
SELECT
COUNT(s01_Products.id)
FROM
s01_Products
LEFT JOIN
s01_Attributes
ON
s01_Attributes.product_id = s01_Products.id
LEFT JOIN
s01_Options
ON
s01_Options.attr_id = s01_Attributes.id
WHERE
(
s01_Products.active = 1
) AND (
(
LEFT(s01_Options.prompt,5) = "Small"
) OR (
LEFT(s01_Options.prompt,2) IN (28,30)
)
)


SELECT
COUNT(s01_Products.id)
FROM
s01_Products
LEFT JOIN
s01_Attributes
ON
s01_Attributes.product_id = s01_Products.id
LEFT JOIN
s01_Options
ON
s01_Options.attr_id = s01_Attributes.id
WHERE
(
s01_Products.active = 1
) AND (
(
LEFT(s01_Options.prompt,6) = "Medium"
) OR (
LEFT(s01_Options.prompt,2) IN (32)
)
)
And one for Large and Extra Large...

I would obviously like to combine all 4 queries in to 1 so that I can get my 4 counts in a single,

Select Statement From Multiple Tables
how can I do this type of join:

table1: id, value1, value2
table2: id, value1, value2
table3: id, value1, value2

the "id" is a product code
the values are new & used pricing

I need a select that can join all this data, and fill 0's if an id is
not listed in a gven table, then output to a file like so:

id, table1.value1, table1,value2, table2.value1, table2.value2,
table3.value1, table3.value2

obviously, if I join on all the ids, it only will output the values
that have the same id in every table. how do I get that plus all the
values that are unique to each table?

Syntax For Multiple Table Sql Select Statement
I have 3 tables as below:

Room (roomId, noBeds)
RoomBooking (roomBookingId, bookingId, roomId)
Booking (bookingId, checkInDate, stayLengthNights)

where Room is linked to RoomBooking by roomId, and RoomBooking is linked to Booking by bookingId.

What I am trying to do is list all of the rooms available for rent between 2 inclusive dates. The statement I have sofar is below, and I understand in the first half of the statement in the where clause is not correct but I just cant figure out how to do it.

Code:

Accessing Multiple Tables With A Select Statement
I am writing a select statement, that says something to this effect. Select * from texas, california, oklahoma; Everything in each table is going to be the exact same. as far as city, name, and zip...they are the titles of my fields. But when I go and look at this file, it just shows everyone from oklahoma. If take out out oklahoma, then it shows everyone from california but not texas. What is the proper way to do this?

Multiple COUNTs Against A Single Table
I want to get some counts from a single database table and I can't figure out how (or if) I can do it in one statement. I have a table of private messages and would like to get counts on new, read and trashed messages for a user. The table:

pms
----
msgID (int) (idx)
toUserID (int)
fromUserID (int)
msgSubject (varchar)
msgBody (text)
msgRead (enum 'y','n')
msgTrashed (enum 'y','n')

I would love to do know if it can be done without using multiple separate COUNT queries. Any way you can do this with one query? Right now I'm using 3 SELECT queries which all check against the toUserID...

new: SELECT COUNT(*) FROM pms WHERE toUserID=1 AND msgRead='N' AND msgTrashed='N'

read: SELECT COUNT(*) FROM pms WHERE toUserID=1 AND msgRead='Y' AND msgTrashed='N'

trashed: SELECT COUNT(*) FROM pms WHERE toUserID=1 AND msgTrashed='Y'

Select / Insert Multiple Rows As A Single Row Of Multiple Columns
I have a nice database set up that contains information about orders and the items on those orders. If an order has 10 items on it, I can select the item data which returns 10 rows of data (let's say 5 colums each). Beautiful!

Now I find myself needing to satisfy a program that requires all of the data on a single row. I can do this in a higher level language, but if I could accomplish it all in mysql it would be better.

I don't need to sum or do any calculations. I just want to select those 5 columns of data about those 10 rows worth of items as a single row with 50 columns.

For example, I'd want this:
1-1,1-2,1-3,1-4,1-5
2-1,2-2,2-3,2-4,2-5

To become:
1-1,1-2,1-3,1-4,1-5,2-1,2-2,2-3,2-4,2-5

The first complication is that the number of items on an order is variable, but is always at least 1 and can not exceed 20. The closest I've been able to get is to do something like:

SELECT GROUP_CONCAT(item_number,",",qty,","",description,"",",price,",",location_number SEPARATOR ",") FROM items WHERE order_number=12345

This will give me a single text string containing the value content of the INSERT query (which will need to be manipuated outside of the SQL query to pad it with NULL values for the unused items' columns etc).

Select Statement Trouble...
I thought I could do a comparison in my SQL statement and get data from Wednesday to Wednesday but I do not know how to tell if my date of entry (which is set with the function NOW() when I write to the database) falls in the most current week.

Some psuedo code would be - Select * from conference_dates where date_of_submission is >= the previous wednesday and date_of_submission is <= today (meaning any day).

I can get any 7 days previous but I am not sure how to get only the number of days necessary (today would return 1 days records).

Trouble With SELECT Statement
I start to work with MySQL to store infos of my private group of dancers. There I have different tables (personen, addresses, emails, phones, urls)

I like to display the infos for all members of this group on a website (php & mysql), but I have trouble with my MySQL statement :

SELECT DISTINCT
concat(firstname," ",name) AS Mitgliedsname,
concat(area,"-",number) AS Telefonnummer,
mail_address AS 'Email-Adresse',
concat(street," ",houseno,", ",zipcode," ",city) AS Anschrift
FROM personen
LEFT JOIN phones ON phones.owner = personen.id
LEFT JOIN emails ON emails.owner = phones.owner
LEFT JOIN addresses ON addresses.owner = emails.owner
WHERE personen.status="Active"
ORDER BY Mitgliedsname;

Some of the members have more than one emailaddress and more than one phonenumber. So when I use the sql statememt above I got multiple combination of some members. here an example of the sql result:

Hans 8386884 hans@web.de Street 18, D-11111 Munich
Hans 7927678 hans@web.com Street 18, D-11111 Munich
Hans 751036 hans@web.net Street 18, D-11111 Munich
Hans 7927678 hans@web.de Street 18, D-11111 Munich
Hans 751036 hans@web.com Street 18, D-11111 Munich
Hans 8386884 hans@web.net Street 18, D-11111 Munich
Hans 751036 hans@web.de Street 18, D-11111 Munich
Hans 8386884 hans@web.com Street 18, D-11111 Munich
Hans 7927678 hans@web.net Street 18, D-11111 Munich

Does anyone of you have an idea how I can solve this?

Multiple Joins
My database has three tables with the following fields:

--tblIngredients--
IngredientID
Ingredient
IngredientInfo

--tblRecipeIngredients--
RecipeIngredientID
RecipeID
IngredientID
Quantity

--tblRecipe--
RecipeID
RecipeName
Directions

tblRecipeIngredients is a join table to link each recipe from tbRecipe with it's respective ingredient(s) from tblIngredients.

Now, I'm trying to write a query that will return all recipe names (RecipeName) that don't have each of the Ingredients specified. In other words, I'm going to have a form that allows the user to select their on-hand ingredients and I want the query to eliminate all the recipes that include ingredients that the user does not have on hand and return the rest. I hope I'm making sense here...

Anyhow, this is what I have so far, but it doesn't work the way I would like it to:

Multiple Joins
How can one link two fields in one table to single field (Primary key) in another table in a single (left join) query, to return two values? e.g.

Table 1
ID (PK)
...other fields
Departure_ID
Arrival_ID
...other fields

"places" table
Place_ID
Placename (value to use in view)

I think this is illegal but, more probably, impossible; perhaps someone could suggest an alternative methodology.

Multiple Joins
I'm modifying a WordPress theme to suit my needs and i'm struggling with the way WP has setup their database. I'm trying to setup a Query that will match a Post with it's Category ID, then match the category id with the category name. I need some sort of INNER or LEFT join in there, but I don't know which type of Join to use.

here's what i have CODESELECT *, DATE_FORMAT($wpdb->posts.post_date,'%c.%e.%Y') AS post_date2 FROM $wpdb->posts LEFT JOIN $wpdb->post2cat ON $wpdb->posts.ID = $wpdb->post2cat.category_id INNER JOIN $wpdb->categories ON $wpdb->post2cat.category_id = $wpdb->categories.cat_ID WHERE $wpdb->posts.post_date < '$now' AND $wpdb->posts.post_status = 'publish' ORDER BY $wpdb->posts.post_date DESC

Problem With Multiple Joins
I have a database with three tables - eaGroups, eaGroupDelegates and eaDelegates.

Groups can hold multiple delegates and delegates can belong to more than one group, so I have used a link table (eaGroupDelegates).

What I need to do is return a list of groups that have a 'client' field set to a specific value, along with a count of the number of delegates in each group that don't have 1 in their 'deleted' field.

I thought the following statement should work, but it returns a high number of delegates, even though it should return none (i.e. there are actually no delegates in the groups for client 13). It does return the right groups, though.

SELECT eaGroups.id, eaGroups.name, eaGroups.parent, eaGroups.level, COUNT(link.delegate) AS delegateCount FROM eaGroups LEFT JOIN (eaGroupDelegates link INNER JOIN eaDelegates delegate ON link.delegate=delegate.id AND delegate.deleted=0) ON link.groupID=eaGroups.id WHERE eaGroups.client=13 GROUP BY eaGroups.id ORDER BY level, name


Multiple LEFT JOINs
I have four tables which I want to join to a table with "complete" information.
There are about 2000 rows in each table.

When I try a multiple LEFT JOIN it works as it should but I takes about 20 seconds or more.

How do I optimize a query to handle many rows? What other JOIN-methods can I use for this?
Should I index in any special way?

Multiple Joins Expensive?
I need to extract some information which comes from two of several tables. I have a query with multiple joins - kind of like this:

SELECT
M.MessageID, C.ConversationID, M.SentDate, M.ReadDate, M.Read,
M.Sender, M.Receiver, M.Subject, M.Body, M.Answered,
M.LetterCategory, M.Type,
FROM Messages M
INNER JOIN MessagesInConversations C ON M.MessageID = C.MessageID
INNER JOIN Translators T1 ON M.Sender = T1.Username
INNER JOIN Translators T2 ON M.Receiver = T2.Username
INNER JOIN Admin A1 ON M.Sender = A1.Username
INNER JOIN Admin A2 ON M.Receiver = A2.Username

WHERE blah blah blah

My question is how inefficient is it to have so many joins? Is it ok, or should I restructure the data in some other way.

Multiple Queries VS Joins
I am working on a project that utilizes a relational database.So far I have been opting for one larger query with multiple join clauses as opposed to multiple select queries.  I had a co-worker raise question over my approach,so I am looking for some outside input.

So far I have been unable to locate any articles concerning the issue, so I would like to ask what other's views on the subject are, or if anyone knows where any articles on the subject can be found.

Using Joins Or Multiple Queries
I have two very large tables, with relational id's. Would it be faster to
1. use a join on the two tables?
2. make two queries

If I were to make two queries would it be faster to use '...WHERE FIND_IN_SET(...' or to use '...WHERE IN(...'

Multiple Joins In Each Record
I'm a relatively inexperienced SQL newbie but need to do the following ...
I have two mysql tables:

tbl_clients
which includes fields: mgr and sp

the above two fields store the ids of emps
e.g
mgr 2
sp  3

and
tbl_emps
which includes fields: emp_id, emp_fname
e.g
1 Fred
2 Sue
3 Bert
I need to construct a SQL query that returns the names in place of the emp ids. e.g:

Multiple Left Joins In One Table
When doing multiple left joins in one table: for each join, which table is considered to be the "left" table (ie: all results must be returned).

Problem With Multiple JOINS To The Same Table
I've got a problem with a site I'm developing. I have a table for press releases which has three drop down menus so that they can store up to three themes with each press release, stored as news.Theme1, news.Theme2 and news.Theme3. They're all populated from the same lookup table, called 'themes'.

I didn't want to create a joining table if I could avoid it (even though I know that's the best way to normalise the data), as they only wanted a maximum of three themes, so I thought this would save me writing so editing pages in their CMS.

If I wanted to write a JOIN to get one of them out in a recordset, I'd do something like:

SELECT news.newsNo, news.newsDate, news.newsTitle, themes.themeName
FROM news
LEFT JOIN themes on news.newsTheme1 = themes.themeNo
ORDER BY newsDate DESC

which works fine.

However, I want to pull out all three themes. I can't find a way to save the results of the JOIN with a different name, to make the themes.themeName record pulled out by the SELECT statement unique.

SELECT news.newsNo, news.newsDate, news.newsTitle, themes.themeName
FROM news
LEFT JOIN themes on news.newsTheme1 = themes.themeNo
LEFT JOIN themes on news.newsTheme2 = themes.themeNo
LEFT JOIN themes on news.newsTheme3 = themes.themeNo
ORDER BY newsDate DESC

Obviously doesn't work

Count On Multiple Table Joins
I have 3 tables: COURSE, USER_COURSE, COURSE_TOPICS

What I am trying to do is select all the rows of COURSE and have a count of all users on each course and a count of the topics assigned.

Id normally write that as an inline select in oracle but it seems Mysql doesnt work in quite the same way!

Using an outer join on just COURSE to USER_COURSE i got it to work:

select c.*, count(uc.course_id) as no_of_members from course c
LEFT OUTER JOIN user_course uc ON c.course_id = uc.course_id
group by course_id;

So following that example I then added an extra join to COURSE_TOPIC to get the count of topics:

select c.*, count(uc.course_id) as no_of_members, count(ct.topic_id) from course c
LEFT OUTER JOIN user_course uc ON c.course_id = uc.course_id
LEFT OUTER JOIN course_topic ct ON c.course_id = ct.course_id
group by course_id

but it returns the wrong figures for both counts!

Indexing Effeciently With Multiple Left Joins
Can anyone point me in the right direction here.
Tell me what to do, or where to find information?

I am trying to access a PHP page and it takes too long.
The problem is the SQL code is in not efficient.

How do you index effieciently with Joins?

The code has four Left Joins.
Looks something like:

$sql = "SELECT
distinct(hi.item_id),
hi.*,
CONCAT(c.contact_first_name,' ',c.contact_last_name) assigned_fullname,
c.contact_email as assigned_email,
p.project_id,
p.project_person,
p.project_color_identifier,
his.status_date
FROM helpdesk_items hi
LEFT JOIN helpdesk_item_status his ON his.status_item_id = hi.item_id
LEFT JOIN users u ON u.user_id = hi.item_assigned_to
LEFT JOIN contacts c ON c.contact_id = u.user_contact
LEFT JOIN projects p ON p.project_id = hi.item_project_id
WHERE $where" .

Multiple Insert Statement
Just wanted to know whether its possible to insert multiple feilds in different tables inj one nested query
There are nested queries for SELECT statement like join etc
Is it possible in case of INSERT statements as well

How To Set Multiple Statement In MyODBC Connectionstring
http://dev.mysql.com/doc/refman/5.0/en/myodbc-configuration-connection-parameters.html
If I want to set multiple command lines in "stmt" parameter, how to do that?

My current connection string
strConn = "Driver={MySQL ODBC 3.51 Driver}; Server=localhost; CharSet=utf8; Port=3306; Option=0; Socket=; Stmt=SET names 'utf8' Database=yyy; Uid=xxx; Pwd=zzz;"

LAST_INSERT_ID With Multiple INSERT Statement
i have the following question:

When inserting many entries into a table with 1 auto_increment key-attibute
(say attribute user_id) and one data attribute (say attribute name)

CREATE users(user_id int key auto_increment, name text)

like

INSERT INTO users(name) VALUES ('pete'),('josh'),('carl')

When the inserting is done in a concurrent way (say 5 scripts do inserting operations like the one above) how do I get the autoincremented ids for all the inserted rows ? I know that LAST_INSERT_ID() yields the autoinc id of the first inserted row (of the multi-insert statement) say 1002 for 'pete' in this case and is also concurrent-safe. But is the insert statement atomic that i can assume that the subsequent generated ids for 'josh' and 'carl' are consecutive i.e. 'josh' gets 1003 and 'carl' gets 1004 when many scripts insert into this table ?

I dont want to use a subsequent SELECT statement to fetch the auto_incremented ids.

How Do I Write Multiple Conditions In An MySQL IF Statement?
I am using version 3.23 and want to write something like this:

Multiple Items In An ALTER TABLE Statement
Was in the midst of doing something today and I attempted to drop a
number of columns in a table with the following:

ALTER TABLE tmp DROP COLUMN col_1, col_2, col_3, col_4;

Unfortunately MySQL gave me an error reading:

ERROR 1064: 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 'col_2, col_3, col_4' at line 1

Can you not have multiple columns names in an alter statement?

Multiple Prepare Statement Inside The Procedure
I'm trying with the multiple dynamic queries inside the stored procedure means, inside my stored procedure i want to execute Multiple queries (DDL and DML). for that i'm storing query in variable and then executting it by prepare stmt.

It works fine with singal prepare stmt and failes for the multiple prepare stmt.

Is there any solution to execute multiple queries inside the Stored procedures or Functions?

Performance Between Multiple INSERT Statements Vs Single Statement With Lots Of Data
$sql1 = "INSERT INTO mytable VALUES ("zzz","xxx")";
$result = mysql_query ($sql1);
...
$sql1000 = "INSERT INTO mytable VALUES ("zzz1000","xxx1000")";
$result = mysql_query ($sql1000);
vs

$sql = "INSERT INTO mytable VALUES
("zzz","xxx"),
...
("zzz1000","xxx1000")";
$result = mysql_query ($sql);

is there any performance difference between the 2?

btw, there could 1000-5000 row inserts.

Connect/ Join Query Multiple Dbs Multiple Servers
Struggling to connect simultaneously to remotehost@my_ip_address
AND localhost@my_field_db FROM my_field_tablet_pc to affect
a custom sycnchronization that SQLyog will not allow.

Both remotehost and localhost are built on WAMP stacks.

Multiple Select
I've the following quries, can I changed these to one query?

PHP

SELECT heading as next_page FROM table WHERE id=10
SELECT heading as previous_page FROM table WHERE id=8
SELECT heading as contents_page FROM table WHERE id=1

How-to Multiple Select
I'm studying a blog program.

Given two tables : post and comment, i would like to retreve the number
of comments for each post.
In postgres the following is doable :

select id, title, body, (select count(*) from comment where post_id =
post.id) as total_comment from post

How-to do the same thing with MySQL?

Extract Multiple Columns From Multiple Tables
For hours and hours I've been trying to work out how to write the sql query to extract some data from some tables, but with no luck.....

How Do I InnoDB Multiple Tablespaces, On Multiple Disks?
I want to use multiple tablespaces with InnoDB tables.

And I also want to spread my InnoDB tables on two separate disks.

I also want to control which disk each of the InnoDB tables are placed.

Is this possible?

Multiple Condition Select
I have an issue with a select that I needed a little help with. I have the following table structure with some sample data:

user_id, group_id, type
11, 1, 1
11, 2, 1
11, 3, 2
11, 4, 3
11, 6, 4
12, 1, 1
13, 3, 2
14, 1, 5
15, 3, 6

What I need to do is select all of the user_id's that have a group_id record of 1 AND 6. I tried a couple of things but I want to make sure I am doing this correctly.

Also, if this is not the correct forum, can someone point me to the correct one? I could not find anything for SQL syntax.

Multiple Select And A Formula
So i have a problem, i run into a more complicate query, at least for me is complicate.

I have more tables but in my example will be just 3.

users (id,nick)
comm (id,userID)
rev (id,userID)

In fact, i need to calculate from the query directly the users points, Each user receive a number of points for each comm, rev he has... For a single user it`s simple, i made the maths in php, but now i need a user TOP.

user points = COUNT(comm.id)*x + COUNT(rev.id)*y

I need to count how many comm and rev has every user, that`s easy. Next i need them to multiply each one by a number, i used count()*x, is easy. The problem begins now, how i make a variable user points,

I start something but it desn`t work fine,

SELECT COUNT(stiri_comm.id) AS 'nrComm',
COUNT(mmorpg_reviews.id) AS 'nrRev' ,users.*
from stiri_comm,mmorpg_reviews,users
WHERE users.id = stiri_comm.userID AND users.id = $id AND stiri_comm.ok=1
AND users.id = mmorpg_reviews.userID AND mmorpg_reviews.ok=1
GROUP BY users.nick;

the result is : nrComm = nrRev = max (nrRev,nrComm) and it`s wrong, i don`t know why.

Select Sum(x) &gt;0 With Multiple Columns
I am writing a script to show the average value of a question in a submitted survey form.

I have 14 questions, which can have the value 1-10, if the user submitts "I don't know" it returns the value 0.

When i calculate the average it includes the value 0 but still divides with all the submitted answers (see code).

How can i make a select statement which only includes values > 0?

Current select statement:

$select = "SELECT SUM(S1), SUM(S2), SUM(S3), SUM(S4), SUM(S5), SUM(S6)
, SUM(S7), SUM(S8), SUM(S9), SUM(S10), SUM(S11)
, SUM(S12), SUM(S13), SUM(S14)
FROM Evaluering";

I want it to do something like this :

$select = "SELECT SUM(S1), SUM(S2), SUM(S3), SUM(S4), SUM(S5), SUM(S6)
, SUM(S7), SUM(S8), SUM(S9), SUM(S10), SUM(S11)
, SUM(S12), SUM(S13), SUM(S14)
WHERE S1,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S12,S13,S14 > 0
FROM Evaluering";

Any suggestions?

Select With Multiple Tables
I have a select coded like: "SELECT * FROM Table1, Table2, Table3 WHERE Key1='Joesmith'"

the query works correctly except that both Table1 and Table2 has a column named "Points"

What is the proper way to retrieve the correct column named Points? I tried "Table1.Points and that failed. I changed the order of table names and then I retrieved the one I wanted (ie. Table2). It appears that if two tables have the same colun name that the one referenced is the last one listed.

Multiple WHERE Statements In SELECT
How can I have more than one WHERE clause, like this:

SELECT
DISTINCT email FROM ehousebo WHERE
waterway="1000 Islands"
OR waterway="Alum Creek Lake"

I tried using HAVING, but that gave an "unknown column" error.

SELECT
DISTINCT email FROM ehousebo HAVING
waterway="1000 Islands"
OR waterway="Alum Creek Lake"

Invalid query: Unknown column 'waterway' in 'having clause'

Select With Multiple Conditions
I've a table called tag_log.

In this table are two columns called tag_id and sub_id. This table is used to link tag names to stories.

I'm trying to write the query for a search. The search is looking for all the sub_id that matches the tag_id given.

Example of what I have currently:
select distinct(sub_id) from tag_log where tag_id in(101, 102, 103);

In the above example, it was performing a union instead of what I really want. It was returning results that have either one or all of the tags.

What's required is for the story to have ALL the three tags. It's should be like a typical search, where the more search terms you enter, the more focused the results will be.

Multiple Database Select
How do I at the best way perform select statements over multiple
databases?

I have a couple of databases containing the same table definitions with
diffrent data. Now I want them to act as a single database giving me
one answer on a select statement but the answer fetched from all my
defined databases.

Right now the databases are on the same node and I guess it is possible
to do something like:

select * from db1.table1, db2.table1 etc etc. but I really do not want
to modify all my sql statements if another database would comes into
picture or is revoved from the set.

Multiple Row Select Issue
Why won't this work? I just get blank page.

$result = mysql_query("SELECT $filt FROM charts WHERE vmanuf IN ('$manuf') ORDER BY $order") or die (mysql_error());

where $manuf = 'string1, string2, etc...' (when the string is one, it works).

Select Multiple Rows With The Same Id
So I have this table:

table_name

id_one ---- id_two
1 ---------- 1
1 ---------- 2
1 ---------- 3
2 ---------- 1
2 ---------- 3

I want to select all of the id_one rows where the id_two is '1' and '2'. The desired output is:

id_one
1
1

Later I might use SELECT DISTINCT to produce the following:

id_one
1

So far I have:

SELECT id_one FROM table_name WHERE id_two IN ('1','2')

But this selects all the id_one rows where id_two is '1' OR '2'. I want the rows where it is '1' AND '2'.

Select From Multiple Tables
I have multiple tables named like this wpctchie, wpctchee, wpcbasfr, wpcbasth etc. The idea is that admin will be able to search all tables beginning "wpc" (all tables), superusers will be a able to browse tables beginning "wpctch" ("wpctchie" and "wpctchee") and users will be able to search only one table e.g "wpctchie"

Is it possible to do a search such as

SELECT * FROM wpc% (for admin)
SELECT * FROM wpctch% (superusers)
SELECT * FROM wpctchie (well this just works anyway!)

Does that make sense what i am trying to do?

Select From Multiple Tables
What is wrong with this query?Code:

SELECT * FROM armor, etcitem, weapon WHERE armor.item_id = '57' AND weapon.item_id = '57' AND etcitem.item_id = '57';


Copyright © 2005-08 www.BigResource.com, All rights reserved