Questions tagged [multiple-tables]

This tag will generally be used by those unfamiliar with SQL, asking basic questions about joins. In SQL, data is stored in tables. Frequently, queries need data from multiple tables, and the way that they are connected may not be obvious.

823 questions
151
votes
4 answers

Drop multiple tables in one shot in MySQL

How to drop multiple tables from one single database at one command. something like, > use test; > drop table a,b,c; where a,b,c are the tables from database test.
Krunal
  • 2,061
  • 3
  • 13
  • 13
109
votes
6 answers

How to perform Join between multiple tables in LINQ lambda

I am trying to perform a Join between multiple tables in LINQ. I have the following classes: Product {Id, ProdName, ProdQty} Category {Id, CatName} ProductCategory{ProdId, CatId} //association table And I use the following code (where product,…
CiccioMiami
  • 8,028
  • 32
  • 90
  • 151
94
votes
3 answers

SELECT * FROM multiple tables. MySQL

SELECT name, price, photo FROM drinks, drinks_photos WHERE drinks.id = drinks_id yeilds 5 rows (5 arrays), photo is the only unique field in a row. name, price get repeated (here, fanta- name, price repeat 3 times.) How do i get rid of these…
NestedWeb
  • 1,657
  • 2
  • 15
  • 31
71
votes
4 answers

Select from one table matching criteria in another?

I'd really appreciate some help with an SQL query across tables. I realise this sort of thing is asked constantly, but I can't find a similar enough question to make sense of the answers. I want to select rows from table_A that have a corresponding…
user668660
39
votes
6 answers

Insert into multiple tables in one query

Assuming that I have two tables, names and phones, and I want to insert data from some input to the tables, in one query. How can it be done?
yossi
  • 3,090
  • 7
  • 45
  • 65
35
votes
3 answers

Multiple left joins on multiple tables in one query

I've got one master table, which has items stored in multiple levels, parents and childs, and there is a second table which may or may not have additional data. I need to query two levels from my master table and have a left join on my second table,…
DeniseMeander
  • 806
  • 2
  • 9
  • 28
30
votes
8 answers

MySQL WHERE IN

Is there a way (without JOIN) to use the WHERE clause on 2 columns (OR) IN a subquery? Currently, I'm doing WHERE 'col1' IN ( SELECT id FROM table ) OR 'col2' IN ( SELECT id FROM table ) And I'm sure I can do better :) . i've also tried…
Max13
  • 919
  • 2
  • 9
  • 27
26
votes
3 answers

Select the minimum value for each row join by another table

I have the following table: Table1 Table2 CardNo ID Record Date ID Name Dept 1 101 8.00 11/7/2013 101 Danny Green 2 101 13.00 11/7/2013 102 …
wood
  • 275
  • 1
  • 3
  • 7
18
votes
1 answer

Postgres full text search across multiple related tables

This may be a very simplistic question, so apologies in advance, but I am very new to database usage. I'd like to have Postgres run its full text search across multiple joined tables. Imagine something like a model User, with related models…
William Jones
  • 18,089
  • 17
  • 63
  • 98
17
votes
3 answers

Multi Table Inheritance with rails 3

Are there standards or best practices yet when it comes to multi table inheritance in rails 3? So far the best article I could find was: http://mediumexposure.com/multiple-table-inheritance-active-record/ But even that needed some changes(e.g.…
jtesch
  • 778
  • 1
  • 7
  • 9
16
votes
8 answers

MySQL: how to drop multiple tables using single query?

I want to drop multiple tables with ease without actually listing the table names in the drop query and the tables to be deleted have prefix say 'wp_'
Angelin Nadar
  • 8,944
  • 10
  • 43
  • 53
16
votes
4 answers

Cakephp Auth with multiple "Users" tables

I would like to know how to deal with only ONE authentification process and "users" in multiple tables. I have 4 Users table: users, admins, artists, teamadmins which all have specific fields, but I would like all of these users to be able to…
Nicolas
  • 2,754
  • 6
  • 26
  • 41
15
votes
7 answers

Should I use flat tables or a normalized database?

I have a web application that I am currently working on that uses a MySQL database for the back-end, and I need to know what is better for my situation before I continue any further. Simply put, in this application users will be able to construct…
15
votes
3 answers

MySQL - Select last record from second table matching with first table

I have two tables customers and orders, below is the structure. Table - customers id customer_name Table - orders id order_id customer_id customers table have customers records and orders table have orders placed by customers, customer_id in…
Alyas
  • 620
  • 1
  • 10
  • 22
12
votes
2 answers

Multiple Table Joins with WHERE clause

I'm using Mysql and I'm having a difficult time trying to get the results from a SELECT query. I am having 3 tables. First table sections, second table section members and third table section member status(data in this table is static). select *…
Bhargav
  • 871
  • 1
  • 13
  • 24
1
2 3
54 55