Hello,
So here is the story:

I'm trying to select from two diferend tables ( bank_wire and visa)

CREATE TABLE IF NOT EXISTS `bank_wire` (
  `id` smallint(6) NOT NULL AUTO_INCREMENT,
  `method_name` char(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'Bank wire',
  `checked` smallint(1) unsigned NOT NULL DEFAULT '1',
  `commision` char(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'No commisions',
  `proccess_time` char(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'Instant',
  `min_deposit` char(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '100 USD',
  `max_deposit` char(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'No limits',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3 ;

--
-- Dump dei dati per la tabella `bank_wire`
--

INSERT INTO `bank_wire` (`id`, `method_name`, `checked`, `commision`, `proccess_time`, `min_deposit`, `max_deposit`) VALUES
(1, 'Bank wire', 1, 'No commisions', 'Instant', '100 USD', 'No limits'),
(2, 'Bank wire 2', 1, 'No commisions', 'Instant', '100 USD', 'No limits');

AND visa TABLE is this equal to bank_wire

CREATE TABLE IF NOT EXISTS `bank_wire` (
  `id` smallint(6) NOT NULL AUTO_INCREMENT,
  `method_name` char(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'Bank wire',
  `checked` smallint(1) unsigned NOT NULL DEFAULT '1',
  `commision` char(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'No commisions',
  `proccess_time` char(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'Instant',
  `min_deposit` char(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '100 USD',
  `max_deposit` char(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'No limits',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3 ;

--
-- Dump dei dati per la tabella `bank_wire`
--

INSERT INTO `bank_wire` (`id`, `method_name`, `checked`, `commision`, `proccess_time`, `min_deposit`, `max_deposit`) VALUES
(1, 'Bank wire', 1, 'No commisions', 'Instant', '100 USD', 'No limits'),
(2, 'Bank wire 2', 1, 'No commisions', 'Instant', '100 USD', 'No limits');

By now i have this php code to select 1 table :

<?php
include '../update/db.php';

$sql = "SELECT *  FROM bank_wire WHERE id =1 and  checked =1  ORDER by id ASC ";
$result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR);
while($row = mysql_fetch_array($result)){

echo "<tr><td>";
 echo $row['method_name'];
echo "</td>";
echo "<td>";
 echo $row['commision'];
echo "</td>";
echo "<td>";
 echo $row['proccess_time'];
echo "</td>";
echo "<td>";
 echo $row['min_deposit'];
echo "</td>";
echo "<td>";
 echo $row['max_deposit'];
echo "</td></tr>\n";
}
?>

Here goes the question:

Q:| How do i select from two tables where checked =1 and id=1 ?

Thanks..

Depends on the result you are looking for

SELECT * FROM bank_wire bw, visa v WHERE bw.id = 1 AND bw.id = v.id AND bw.checked = 1 AND v.checked = 1

//or

SELECT * FROM bank_wire WHERE id=1 AND checked=1
UNION
SELECT * FROM visa WHERE id=1 AND checked=1
Member Avatar for 1stDAN

Both tables have same name bank_wire. There is no table having name visa.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.